Minor fixes and changes.
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Mon, 19 Sep 2011 16:34:32 +0000 (19:34 +0300)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Mon, 19 Sep 2011 16:34:32 +0000 (19:34 +0300)
pithos-macos/PithosBrowserController.m
pithos-macos/PithosFileUtilities.m

index f8b39fe..7633585 100644 (file)
@@ -565,19 +565,23 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
 
 - (void)downloadObjectFinished:(ASIPithosObjectRequest *)objectRequest {
     NSLog(@"Download completed: %@", [objectRequest url]);
-    if ([objectRequest bytes] == 0) {
-        NSLog(@"Downloaded  0 bytes");
-        NSFileManager *defaultManager = [NSFileManager defaultManager];
-        NSString *filePath = [objectRequest.userInfo objectForKey:@"filePath"];
-        if (![defaultManager fileExistsAtPath:filePath]) {
-            if (![defaultManager createFileAtPath:filePath contents:nil attributes:nil]) {
-                NSAlert *alert = [[[NSAlert alloc] init] autorelease];
-                [alert setMessageText:@"Create File Error"];
-                [alert setInformativeText:[NSString stringWithFormat:@"Cannot create zero length file at %@", filePath]];
-                [alert addButtonWithTitle:@"OK"];
-                [alert runModal];
+    if (objectRequest.responseStatusCode == 200) {
+        if ([objectRequest contentLength] == 0) {
+            NSLog(@"Downloaded  0 bytes");
+            NSFileManager *defaultManager = [NSFileManager defaultManager];
+            NSString *filePath = [objectRequest.userInfo objectForKey:@"filePath"];
+            if (![defaultManager fileExistsAtPath:filePath]) {
+                if (![defaultManager createFileAtPath:filePath contents:nil attributes:nil]) {
+                    NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+                    [alert setMessageText:@"Create File Error"];
+                    [alert setInformativeText:[NSString stringWithFormat:@"Cannot create zero length file at %@", filePath]];
+                    [alert addButtonWithTitle:@"OK"];
+                    [alert runModal];
+                }
             }
         }
+    } else {
+        [PithosFileUtilities unexpectedResponseStatusAlertWithRequest:objectRequest];
     }
 }
 
index f5ef93d..703f063 100644 (file)
                                                       checkIfExists:(BOOL)ifExists 
                                                              hashes:(NSArray **)hashes {
     if (ifExists) {
-        NSString *responseString;
         NSError *error;
         BOOL isDirectory;
-        BOOL objectExists = [self objectExistsAtContainerName:containerName objectName:objectName 
-                                               responseString:&responseString error:&error isDirectory:&isDirectory];
-        NSAlert *alert;
+        BOOL objectExists = [self objectExistsAtContainerName:containerName objectName:objectName
+                                                        error:&error isDirectory:&isDirectory];
         if (error) {
-            alert = [[[NSAlert alloc] init] autorelease];
-            [alert setMessageText:@"HTTP Request Error"];
-            [alert setInformativeText:[NSString stringWithFormat:@"HTTP Request Error: %@", error]];
-            [alert setInformativeText:[NSString stringWithFormat:@"HTTP Request Error: %@\nResponse String: %@", 
-                                       error, responseString]];
-            [alert addButtonWithTitle:@"OK"];
-            [alert runModal];
             return nil;
         } else if (objectExists) {
-            alert = [[[NSAlert alloc] init] autorelease];
+            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
             if (isDirectory) {
                 [alert setMessageText:@"Directory Exists"];
                 [alert setInformativeText:[NSString stringWithFormat:@"A directory with path '%@' in the container '%@' already exists, do you want to replace it?", objectName, containerName]];
         if (error) {
             return nil;
         } else if (objectExists) {
-            if (!isDirectory) {
-                NSAlert *alert = [[[NSAlert alloc] init] autorelease];
-                [alert setMessageText:@"Object Exists"];
-                [alert setInformativeText:[NSString stringWithFormat:@"An object with path '%@' in the container '%@' already exists, do you want to replace it?", objectName, containerName]];
-                [alert addButtonWithTitle:@"OK"];
-                [alert addButtonWithTitle:@"Cancel"];
-                NSInteger choice = [alert runModal];
-                if (choice == NSAlertSecondButtonReturn)
-                    return nil;
-            } else {
-                NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+            if (isDirectory) {
                 [alert setMessageText:@"Directory Exists"];
                 [alert setInformativeText:[NSString stringWithFormat:@"A directory with path '%@' in the container '%@' already exists, do you want to replace it?", objectName, containerName]];
-                [alert addButtonWithTitle:@"OK"];
-                [alert addButtonWithTitle:@"Cancel"];
-                NSInteger choice = [alert runModal];
-                if (choice == NSAlertSecondButtonReturn)
-                    return nil;
+            } else {
+                [alert setMessageText:@"Object Exists"];
+                [alert setInformativeText:[NSString stringWithFormat:@"An object with path '%@' in the container '%@' already exists, do you want to replace it?", objectName, containerName]];
             }
+            [alert addButtonWithTitle:@"OK"];
+            [alert addButtonWithTitle:@"Cancel"];
+            NSInteger choice = [alert runModal];
+            if (choice == NSAlertSecondButtonReturn)
+                return nil;
         }
     }