Directory marker objects can be of content type "application/directory" or "applicati...
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Mon, 31 Oct 2011 17:28:04 +0000 (19:28 +0200)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Mon, 31 Oct 2011 17:28:04 +0000 (19:28 +0200)
pithos-macos/PithosBrowserController.m
pithos-macos/PithosContainerNode.m
pithos-macos/PithosSyncDaemon.m
pithos-macos/PithosUtilities.h
pithos-macos/PithosUtilities.m

index 504f56c..c949d79 100644 (file)
@@ -1093,7 +1093,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
         NSUInteger currentBytes = activity.currentBytes;
         
         // XXX change contentLength to objectContentLength if it is fixed in the server
-        if (([objectRequest contentLength] == 0) && (![[objectRequest contentType] isEqualToString:@"application/directory"])) {
+        if (([objectRequest contentLength] == 0) && ![PithosUtilities isContentTypeDirectory:[objectRequest contentType]]) {
             NSLog(@"Downloaded  0 bytes");
             NSFileManager *fileManager = [NSFileManager defaultManager];
             if (![fileManager fileExistsAtPath:filePath]) {
index 820456a..f29a8fe 100644 (file)
@@ -217,8 +217,8 @@ static NSImage *sharedIcon = nil;
                     // The check above removes false objects due to trailing slash or same prefix
                     if (object.subdir) {
                         NSUInteger sameNameObjectIndex = [objectNames indexOfObject:[object.name substringToIndex:([object.name length] - 1)]];
-                        if ((sameNameObjectIndex == NSNotFound) ||
-                            ![[[objects objectAtIndex:sameNameObjectIndex] contentType] isEqualToString:@"application/directory"]) {
+                        if ((sameNameObjectIndex == NSNotFound) || 
+                            ![PithosUtilities isContentTypeDirectory:[[objects objectAtIndex:sameNameObjectIndex] contentType]]) {
                             PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease];
                             node.parent = self;
                             node.shared = shared;
@@ -237,7 +237,7 @@ static NSImage *sharedIcon = nil;
                                 node.pithosObject.allowedTo = [NSString stringWithString:@"read"];
                             [newChildren addObject:node];
                         }
-                    } else if ([object.contentType isEqualToString:@"application/directory"]) {
+                    } else if ([PithosUtilities isContentTypeDirectory:object.contentType]) {
                         PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease];
                         node.parent = self;
                         node.shared = shared;
index 128258e..fec9018 100644 (file)
             [storedLocalObjectStates removeObjectForKey:object.name];
             [self saveLocalState];
         }
-    } else if ([object.contentType isEqualToString:@"application/directory"]) {
+    } else if ([PithosUtilities isContentTypeDirectory:object.contentType]) {
         // Create local directory object
         NSLog(@"Sync::create local directory object: %@", filePath);
         BOOL directoryCreated = NO;
             PithosLocalObjectState *remoteObjectState = [PithosLocalObjectState localObjectState];
             ASIPithosObject *remoteObject = [remoteObjects objectForKey:objectName];
             if (remoteObject) {
-                if ([remoteObject.contentType isEqualToString:@"application/directory"]) {
+                if ([PithosUtilities isContentTypeDirectory:remoteObject.contentType]) {
                     remoteObjectState.isDirectory = YES;
                     object.contentType = @"application/directory";
                 } else {
index 483afb3..51cec07 100644 (file)
 
 + (NSUInteger)bytesOfFile:(NSString *)filePath;
 + (NSString *)contentTypeOfFile:(NSString *)filePath error:(NSError **)error;
++ (BOOL)isContentTypeDirectory:(NSString *)contentType;
 + (BOOL)objectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName
                               error:(NSError **)error isDirectory:(BOOL *)isDirectory sharingAccount:(NSString *)sharingAccount;
 + (BOOL)proceedIfObjectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName 
index 8fecb7b..151ddb7 100644 (file)
     }
     
     for (ASIPithosObject *object in objects) {
-        if ([object.contentType isEqualToString:@"application/directory"]) {
+        if ([PithosUtilities isContentTypeDirectory:object.contentType]) {
             NSString *subdirDirectoryPath = [directoryPath stringByAppendingPathComponent:subdirName];
             subdirDirectoryPath = [subdirDirectoryPath stringByAppendingPathComponent:[object.name substringFromIndex:subdirPrefixLength]];
             
     return [response MIMEType];
 }
 
+// Returns if an object is a directory based on its content type
++ (BOOL)isContentTypeDirectory:(NSString *)contentType {
+    return ([contentType isEqualToString:@"application/directory"] ||
+            [contentType hasPrefix:@"application/directory;"] ||
+            [contentType isEqualToString:@"application/folder"] ||
+            [contentType hasPrefix:@"application/folder;"]);
+}
+
 // Returns if an object exists at the given container/object path and if this object is an application/directory
 // If an error occured an alert is shown and it is returned so the caller won't proceed
 + (BOOL)objectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName 
         [self httpRequestErrorAlertWithRequest:objectRequest];
         return NO;
     } else if (objectRequest.responseStatusCode == 200) {
-        *isDirectory = [[objectRequest contentType] isEqualToString:@"application/directory"];
+        *isDirectory = [self isContentTypeDirectory:[objectRequest contentType]];
         return YES;
     }
     return NO;