__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;
}
- (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];
[objectRequest startAsynchronous];
}
}
- }];
+ }
return names;
}
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];
}
[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 {
// or implied, of GRNET S.A.
@class ASIPithosRequest;
+@class ASIPithosContainerRequest;
@class ASIPithosObjectRequest;
@interface PithosFileUtilities : NSObject
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
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];
[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