From 3b22507d56e8bceb5c1e0cd01123cd264283b798 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Fri, 30 Sep 2011 14:03:42 +0300 Subject: [PATCH] Blocks are uploaded using container POST. Other minor changes and fixes. --- pithos-apple-common | 2 +- pithos-macos/PithosBrowserController.m | 93 +++++++++++++++----------------- pithos-macos/PithosFileUtilities.h | 25 +++++---- pithos-macos/PithosFileUtilities.m | 64 +++++++++------------- 4 files changed, 82 insertions(+), 102 deletions(-) diff --git a/pithos-apple-common b/pithos-apple-common index 9d03a93..b9ebc0f 160000 --- a/pithos-apple-common +++ b/pithos-apple-common @@ -1 +1 @@ -Subproject commit 9d03a93cefc1d00120c777deb4c692f85b9cbc41 +Subproject commit b9ebc0f4602b7937448a40169a68fe9acd0fe040 diff --git a/pithos-macos/PithosBrowserController.m b/pithos-macos/PithosBrowserController.m index 4ec654a..4103f61 100644 --- a/pithos-macos/PithosBrowserController.m +++ b/pithos-macos/PithosBrowserController.m @@ -480,7 +480,7 @@ __block BOOL result = YES; [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){ PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:idx]]; - if ([node class] == [PithosContainerNode class]) { + if (([node class] == [PithosContainerNode class]) || ([node class] == [PithosAccountNode class])) { result = NO; *stop = YES; } @@ -508,11 +508,8 @@ - (NSArray *)browser:(NSBrowser *)aBrowser namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column { - NSMutableArray *names = [NSMutableArray arrayWithCapacity:[rowIndexes count]]; - NSIndexPath *baseIndexPath = [browser indexPathForColumn:column]; - [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){ - PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:idx]]; - + NSMutableArray *names = [NSMutableArray arrayWithCapacity:[draggedNodes count]]; + for (PithosNode *node in draggedNodes) { // If the node is a subdir ask if the whole tree should be downloaded if ([node class] == [PithosSubdirNode class]) { NSAlert *alert = [[[NSAlert alloc] init] autorelease]; @@ -554,7 +551,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column { [objectRequest startAsynchronous]; } } - }]; + } return names; } @@ -984,20 +981,19 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column { NSIndexSet *missingBlocks = [PithosFileUtilities missingBlocksForHashes:[objectRequest.userInfo objectForKey:@"hashes"] withMissingHashesResponse:[objectRequest responseString]]; NSUInteger missingBlockIndex = [missingBlocks firstIndex]; - ASIPithosObjectRequest *newObjectRequest = [PithosFileUtilities updateObjectDataRequestWithContainerName:[objectRequest.userInfo objectForKey:@"containerName"] - objectName:@".upload" - blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue] - forFile:[objectRequest.userInfo objectForKey:@"filePath"] - missingBlockIndex:missingBlockIndex - sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]]; - newObjectRequest.delegate = self; - newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:); - newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:); - newObjectRequest.userInfo = objectRequest.userInfo; - [(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:iteration] forKey:@"iteration"]; - [(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:missingBlocks forKey:@"missingBlocks"]; - [(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:missingBlockIndex] forKey:@"missingBlockIndex"]; - [newObjectRequest startAsynchronous]; + ASIPithosContainerRequest *newContainerRequest = [PithosFileUtilities updateContainerDataRequestWithContainerName:[objectRequest.userInfo objectForKey:@"containerName"] + blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue] + forFile:[objectRequest.userInfo objectForKey:@"filePath"] + missingBlockIndex:missingBlockIndex + sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]]; + newContainerRequest.delegate = self; + newContainerRequest.didFinishSelector = @selector(uploadMissingBlockFinished:); + newContainerRequest.didFailSelector = @selector(uploadMissingBlockFailed:); + newContainerRequest.userInfo = objectRequest.userInfo; + [(NSMutableDictionary *)(newContainerRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:iteration] forKey:@"iteration"]; + [(NSMutableDictionary *)(newContainerRequest.userInfo) setObject:missingBlocks forKey:@"missingBlocks"]; + [(NSMutableDictionary *)(newContainerRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:missingBlockIndex] forKey:@"missingBlockIndex"]; + [newContainerRequest startAsynchronous]; } else { [PithosFileUtilities unexpectedResponseStatusAlertWithRequest:objectRequest]; } @@ -1008,52 +1004,51 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column { [PithosFileUtilities httpRequestErrorAlertWithRequest:objectRequest]; } -- (void)uploadMissingBlockFinished:(ASIPithosObjectRequest *)objectRequest { - NSLog(@"Upload of missing block completed: %@", [objectRequest url]); - if (objectRequest.responseStatusCode == 201) { - NSIndexSet *missingBlocks = [objectRequest.userInfo objectForKey:@"missingBlocks"]; - NSUInteger missingBlockIndex = [[objectRequest.userInfo objectForKey:@"missingBlockIndex"] unsignedIntegerValue]; +- (void)uploadMissingBlockFinished:(ASIPithosContainerRequest *)containerRequest { + NSLog(@"Upload of missing block completed: %@", [containerRequest url]); + if (containerRequest.responseStatusCode == 202) { + NSIndexSet *missingBlocks = [containerRequest.userInfo objectForKey:@"missingBlocks"]; + NSUInteger missingBlockIndex = [[containerRequest.userInfo objectForKey:@"missingBlockIndex"] unsignedIntegerValue]; missingBlockIndex = [missingBlocks indexGreaterThanIndex:missingBlockIndex]; if (missingBlockIndex == NSNotFound) { - NSArray *hashes = [objectRequest.userInfo objectForKey:@"hashes"]; - ASIPithosObjectRequest *newObjectRequest = [PithosFileUtilities writeObjectDataRequestWithContainerName:[objectRequest.userInfo objectForKey:@"containerName"] - objectName:[objectRequest.userInfo objectForKey:@"objectName"] - contentType:[objectRequest.userInfo objectForKey:@"contentType"] - blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue] - blockHash:[objectRequest.userInfo objectForKey:@"blockHash"] - forFile:[objectRequest.userInfo objectForKey:@"filePath"] + NSArray *hashes = [containerRequest.userInfo objectForKey:@"hashes"]; + ASIPithosObjectRequest *newObjectRequest = [PithosFileUtilities writeObjectDataRequestWithContainerName:[containerRequest.userInfo objectForKey:@"containerName"] + objectName:[containerRequest.userInfo objectForKey:@"objectName"] + contentType:[containerRequest.userInfo objectForKey:@"contentType"] + blockSize:[[containerRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue] + blockHash:[containerRequest.userInfo objectForKey:@"blockHash"] + forFile:[containerRequest.userInfo objectForKey:@"filePath"] checkIfExists:NO hashes:&hashes - sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]]; + sharingAccount:[containerRequest.userInfo objectForKey:@"sharingAccount"]]; newObjectRequest.delegate = self; newObjectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:); newObjectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:); - newObjectRequest.userInfo = objectRequest.userInfo; + newObjectRequest.userInfo = containerRequest.userInfo; [(NSMutableDictionary *)(newObjectRequest.userInfo) removeObjectForKey:@"missingBlocks"]; [(NSMutableDictionary *)(newObjectRequest.userInfo) removeObjectForKey:@"missingBlockIndex"]; [newObjectRequest startAsynchronous]; } else { - ASIPithosObjectRequest *newObjectRequest = [PithosFileUtilities updateObjectDataRequestWithContainerName:[objectRequest.userInfo objectForKey:@"containerName"] - objectName:@".upload" - blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue] - forFile:[objectRequest.userInfo objectForKey:@"filePath"] + ASIPithosContainerRequest *newContainerRequest = [PithosFileUtilities updateContainerDataRequestWithContainerName:[containerRequest.userInfo objectForKey:@"containerName"] + blockSize:[[containerRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue] + forFile:[containerRequest.userInfo objectForKey:@"filePath"] missingBlockIndex:missingBlockIndex - sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]]; - newObjectRequest.delegate = self; - newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:); - newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:); - newObjectRequest.userInfo = objectRequest.userInfo; - [(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:missingBlockIndex] forKey:@"missingBlockIndex"]; - [newObjectRequest startAsynchronous]; + sharingAccount:[containerRequest.userInfo objectForKey:@"sharingAccount"]]; + newContainerRequest.delegate = self; + newContainerRequest.didFinishSelector = @selector(uploadMissingBlockFinished:); + newContainerRequest.didFailSelector = @selector(uploadMissingBlockFailed:); + newContainerRequest.userInfo = containerRequest.userInfo; + [(NSMutableDictionary *)(newContainerRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:missingBlockIndex] forKey:@"missingBlockIndex"]; + [newContainerRequest startAsynchronous]; } } else { - [PithosFileUtilities unexpectedResponseStatusAlertWithRequest:objectRequest]; + [PithosFileUtilities unexpectedResponseStatusAlertWithRequest:containerRequest]; } } -- (void)uploadMissingBlockFailed:(ASIPithosObjectRequest *)objectRequest { +- (void)uploadMissingBlockFailed:(ASIPithosContainerRequest *)containerRequest { NSLog(@"Upload of missing block failed"); - [PithosFileUtilities httpRequestErrorAlertWithRequest:objectRequest]; + [PithosFileUtilities httpRequestErrorAlertWithRequest:containerRequest]; } - (void)moveFinished:(ASIPithosObjectRequest *)objectRequest { diff --git a/pithos-macos/PithosFileUtilities.h b/pithos-macos/PithosFileUtilities.h index 5ad6877..caf666b 100644 --- a/pithos-macos/PithosFileUtilities.h +++ b/pithos-macos/PithosFileUtilities.h @@ -36,6 +36,7 @@ // or implied, of GRNET S.A. @class ASIPithosRequest; +@class ASIPithosContainerRequest; @class ASIPithosObjectRequest; @interface PithosFileUtilities : NSObject @@ -61,19 +62,17 @@ hashes:(NSArray **)hashes sharingAccount:(NSString *)sharingAccount; + (NSIndexSet *)missingBlocksForHashes:(NSArray *)hashes withMissingHashesResponse:(NSString *)missingHashesResponse; -+ (ASIPithosObjectRequest *)updateObjectDataRequestWithContainerName:(NSString *)containerName - objectName:(NSString *)objectName - blockSize:(NSUInteger)blockSize - forFile:(NSString *)filePath - hashes:(NSArray *)hashes - missingHashesResponse:(NSString *)missingHashesResponse - sharingAccount:(NSString *)sharingAccount; -+ (ASIPithosObjectRequest *)updateObjectDataRequestWithContainerName:(NSString *)containerName - objectName:(NSString *)objectName - blockSize:(NSUInteger)blockSize - forFile:(NSString *)filePath - missingBlockIndex:(NSUInteger)missingBlockIndex - sharingAccount:(NSString *)sharingAccount; ++ (ASIPithosContainerRequest *)updateContainerDataRequestWithContainerName:(NSString *)containerName + blockSize:(NSUInteger)blockSize + forFile:(NSString *)filePath + hashes:(NSArray *)hashes + missingHashesResponse:(NSString *)missingHashesResponse + sharingAccount:(NSString *)sharingAccount; ++ (ASIPithosContainerRequest *)updateContainerDataRequestWithContainerName:(NSString *)containerName + blockSize:(NSUInteger)blockSize + forFile:(NSString *)filePath + missingBlockIndex:(NSUInteger)missingBlockIndex + sharingAccount:(NSString *)sharingAccount; + (NSArray *)writeObjectDataRequestsWithContainerName:(NSString *)containerName objectName:(NSString *)objectName blockSize:(NSUInteger)blockSize diff --git a/pithos-macos/PithosFileUtilities.m b/pithos-macos/PithosFileUtilities.m index 8d4b564..be68b9a 100644 --- a/pithos-macos/PithosFileUtilities.m +++ b/pithos-macos/PithosFileUtilities.m @@ -241,13 +241,12 @@ return missingBlocks; } -+ (ASIPithosObjectRequest *)updateObjectDataRequestWithContainerName:(NSString *)containerName - objectName:(NSString *)objectName - blockSize:(NSUInteger)blockSize - forFile:(NSString *)filePath - hashes:(NSArray *)hashes - missingHashesResponse:(NSString *)missingHashesResponse - sharingAccount:(NSString *)sharingAccount { ++ (ASIPithosContainerRequest *)updateContainerDataRequestWithContainerName:(NSString *)containerName + blockSize:(NSUInteger)blockSize + forFile:(NSString *)filePath + hashes:(NSArray *)hashes + missingHashesResponse:(NSString *)missingHashesResponse + sharingAccount:(NSString *)sharingAccount { NSIndexSet *missingBlocks = [self missingBlocksForHashes:hashes withMissingHashesResponse:missingHashesResponse]; NSFileManager *defaultManager = [NSFileManager defaultManager]; @@ -281,46 +280,33 @@ [tempFileHandle closeFile]; [fileHandle closeFile]; - ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName - objectName:objectName - eTag:nil - contentType:@"application/octet-stream" - contentEncoding:nil - contentDisposition:nil - manifest:nil - sharing:nil - isPublic:ASIPithosObjectRequestPublicIgnore - metadata:nil - file:tempFilePath]; + ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest updateContainerDataRequestWithContainerName:containerName + policy:nil + metadata:nil + update:YES + file:tempFilePath]; if (sharingAccount) - [objectRequest setRequestUserFromDefaultTo:sharingAccount]; - return objectRequest; + [containerRequest setRequestUserFromDefaultTo:sharingAccount]; + return containerRequest; } -+ (ASIPithosObjectRequest *)updateObjectDataRequestWithContainerName:(NSString *)containerName - objectName:(NSString *)objectName - blockSize:(NSUInteger)blockSize - forFile:(NSString *)filePath - missingBlockIndex:(NSUInteger)missingBlockIndex - sharingAccount:(NSString *)sharingAccount { ++ (ASIPithosContainerRequest *)updateContainerDataRequestWithContainerName:(NSString *)containerName + blockSize:(NSUInteger)blockSize + forFile:(NSString *)filePath + missingBlockIndex:(NSUInteger)missingBlockIndex + sharingAccount:(NSString *)sharingAccount { NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; [fileHandle seekToFileOffset:(missingBlockIndex *blockSize)]; NSData *blockData = [fileHandle readDataOfLength:blockSize]; [fileHandle closeFile]; - ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName - objectName:objectName - eTag:nil - contentType:@"application/octet-stream" - contentEncoding:nil - contentDisposition:nil - manifest:nil - sharing:nil - isPublic:ASIPithosObjectRequestPublicIgnore - metadata:nil - data:blockData]; + ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest updateContainerDataRequestWithContainerName:containerName + policy:nil + metadata:nil + update:YES + data:blockData]; if (sharingAccount) - [objectRequest setRequestUserFromDefaultTo:sharingAccount]; - return objectRequest; + [containerRequest setRequestUserFromDefaultTo:sharingAccount]; + return containerRequest; } + (NSArray *)writeObjectDataRequestsWithContainerName:(NSString *)containerName -- 1.7.10.4