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]) {
// 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;
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;
[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 {
+ (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
}
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;