aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Storage/FIRStorageMetadata.m
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2017-09-06 14:37:04 -0700
committerGravatar GitHub <noreply@github.com>2017-09-06 14:37:04 -0700
commite8e0916c2ae24ec14130b1dc00f9574d78940462 (patch)
tree92554ccf9e084f62546b85ad035e71c005a3d67a /Firebase/Storage/FIRStorageMetadata.m
parent96685dfbb9936ec9b875491ccad9891231afd7ba (diff)
Firebase Storage: Allowing metadata to be cleared (#197)
* Allowing metadata to be cleared
Diffstat (limited to 'Firebase/Storage/FIRStorageMetadata.m')
-rw-r--r--Firebase/Storage/FIRStorageMetadata.m37
1 files changed, 36 insertions, 1 deletions
diff --git a/Firebase/Storage/FIRStorageMetadata.m b/Firebase/Storage/FIRStorageMetadata.m
index 4269a45..c4ff5a8 100644
--- a/Firebase/Storage/FIRStorageMetadata.m
+++ b/Firebase/Storage/FIRStorageMetadata.m
@@ -31,6 +31,8 @@
- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
self = [super init];
if (self) {
+ _initialMetadata = [dictionary copy];
+
_bucket = dictionary[kFIRStorageMetadataBucket];
_cacheControl = dictionary[kFIRStorageMetadataCacheControl];
_contentDisposition = dictionary[kFIRStorageMetadataContentDisposition];
@@ -73,7 +75,10 @@
#pragma mark - NSObject overrides
- (instancetype)copyWithZone:(NSZone *)zone {
- return [[[self class] allocWithZone:zone] initWithDictionary:[self dictionaryRepresentation]];
+ FIRStorageMetadata *clone =
+ [[[self class] allocWithZone:zone] initWithDictionary:[self dictionaryRepresentation]];
+ clone.initialMetadata = [self.initialMetadata copy];
+ return clone;
}
- (BOOL)isEqual:(id)object {
@@ -200,6 +205,36 @@
return [_downloadURLs firstObject];
}
+#pragma mark - Private methods
+
++ (void)removeMatchingMetadata:(NSMutableDictionary *)metadata
+ oldMetadata:(NSDictionary *)oldMetadata {
+ for (NSString* metadataKey in [oldMetadata allKeys]) {
+ id oldValue = [oldMetadata objectForKey:metadataKey];
+ id newValue = [metadata objectForKey:metadataKey];
+
+ if (oldValue && !newValue) {
+ [metadata setObject:[NSNull null] forKey:metadataKey];
+ } else if ([oldValue isKindOfClass:[NSString class]] &&
+ [newValue isKindOfClass:[NSString class]]) {
+ if ([oldValue isEqualToString:newValue]) {
+ [metadata removeObjectForKey:metadataKey];
+ }
+ } else if ([oldValue isKindOfClass:[NSDictionary class]] &&
+ [newValue isKindOfClass:[NSDictionary class]]) {
+ NSMutableDictionary *nestedMetadata = [newValue mutableCopy];
+ [self removeMatchingMetadata:nestedMetadata oldMetadata:oldValue];
+ [metadata setObject:[nestedMetadata copy] forKey:metadataKey];
+ }
+ }
+}
+
+- (NSDictionary *)updatedMetadata {
+ NSMutableDictionary *metadataUpdate = [[self dictionaryRepresentation] mutableCopy];
+ [FIRStorageMetadata removeMatchingMetadata:metadataUpdate oldMetadata:_initialMetadata];
+ return [metadataUpdate copy];
+}
+
#pragma mark - RFC 3339 conversions
static NSDateFormatter *sRFC3339DateFormatter;