Fix bug in container model
[pithos-ios] / Classes / Container.m
index 038fe26..d2cd6fb 100755 (executable)
     Container *container = [[[Container alloc] init] autorelease];
     // regular attributes
     container.name = [dict objectForKey:@"name"];
-    container.count = [[dict objectForKey:@"count"] unsignedIntegerValue];
-    container.bytes = [[dict objectForKey:@"bytes"] unsignedLongLongValue];
-    
-    //policy
-    container.versioning = [[dict objectForKey:@"x_container_policy"] objectForKey:@"versioning"];
-    // we lose precision in the quota for now, this should be turned to unsigned long long
-    container.quota = strtoul([[[dict objectForKey:@"x_container_policy"] objectForKey:@"quota"] UTF8String], NULL, 0);
-    
-    // metadata
-    container.metadata = nil;
+    if ([dict objectForKey:@"count"]) {
+        // If "count" doesn't exist then it is a "shared to me" container, where only "name" exists
+        container.count = [[dict objectForKey:@"count"] unsignedIntegerValue];
+        container.bytes = [[dict objectForKey:@"bytes"] unsignedLongLongValue];
+        
+        // policy
+        container.versioning = [[dict objectForKey:@"x_container_policy"] objectForKey:@"versioning"];
+        // we lose precision in the quota for now, this should be turned to unsigned long long
+        container.quota = strtoul([[[dict objectForKey:@"x_container_policy"] objectForKey:@"quota"] UTF8String], NULL, 0);
+    }
+    // metadata are created elsewhere, so are left nil
     
     return container;
 }