if ([PithosFileUtilities objectExistsAtContainerName:node.pithosContainer.name
objectName:destinationObjectName
error:&error
- isDirectory:&isDirectory]) {
+ isDirectory:&isDirectory
+ sharingAccount:nil]) {
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Name Taken"];
[alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
if ([PithosFileUtilities objectExistsAtContainerName:node.pithosContainer.name
objectName:destinationObjectName
error:&error
- isDirectory:&isDirectory]) {
+ isDirectory:&isDirectory
+ sharingAccount:nil]) {
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Name Taken"];
[alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
if (*row != -1) {
// Check if the node is not a folder and if so redirect to the parent item
dropNode = [browser itemAtRow:*row inColumn:*column];
- if ([dropNode class] != [PithosSubdirNode class])
+ if ([dropNode class] == [PithosObjectNode class])
*row = -1;
}
if (*row == -1)
dropNode = [browser parentForItemsInColumn:*column];
- if (!dropNode.shared && !dropNode.sharingAccount) {
+ if (!dropNode.shared &&
+ (!dropNode.sharingAccount ||
+ ([dropNode class] == [PithosSubdirNode class]) ||
+ ([dropNode class] == [PithosContainerNode class]))) {
*dropOperation = NSBrowserDropOn;
result = NSDragOperationCopy;
}
if (*row != -1) {
// Check if the node is not a folder and if so redirect to the parent item
dropNode = [browser itemAtRow:*row inColumn:*column];
- if ([dropNode class] != [PithosSubdirNode class])
+ if ([dropNode class] == [PithosObjectNode class])
*row = -1;
}
if (*row == -1)
blockHash:blockHash
forFile:filePath
checkIfExists:YES
- hashes:&hashes];
+ hashes:&hashes
+ sharingAccount:node.sharingAccount];
if (objectRequest) {
objectRequest.delegate = self;
objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
- objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- containerName, @"containerName",
- objectName, @"objectName",
- contentType, @"contentType",
- [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize",
- blockHash, @"blockHash",
- filePath, @"filePath",
- hashes, @"hashes",
- node, @"node",
- [NSNumber numberWithUnsignedInteger:10], @"iteration",
- nil];
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ containerName, @"containerName",
+ objectName, @"objectName",
+ contentType, @"contentType",
+ [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize",
+ blockHash, @"blockHash",
+ filePath, @"filePath",
+ hashes, @"hashes",
+ node, @"node",
+ [NSNumber numberWithUnsignedInteger:10], @"iteration",
+ nil];
+ if (node.sharingAccount)
+ [userInfo setObject:node.sharingAccount forKey:@"sharingAccount"];
+ objectRequest.userInfo = userInfo;
[objectRequest startAsynchronous];
}
});
contentTypes:&contentTypes
filePaths:&filePaths
hashesArrays:&hashesArrays
- directoryObjectRequests:&directoryObjectRequests];
+ directoryObjectRequests:&directoryObjectRequests
+ sharingAccount:node.sharingAccount];
for (ASIPithosObjectRequest *objectRequest in directoryObjectRequests) {
objectRequest.delegate = self;
objectRequest.didFinishSelector = @selector(uploadDirectoryObjectFinished:);
objectRequest.delegate = self;
objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
- objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- containerName, @"containerName",
- [objectNames objectAtIndex:i], @"objectName",
- [contentTypes objectAtIndex:i], @"contentType",
- [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize",
- blockHash, @"blockHash",
- [filePaths objectAtIndex:i], @"filePath",
- [hashesArrays objectAtIndex:i], @"hashes",
- [NSNumber numberWithUnsignedInteger:10], @"iteration",
- nil];
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ containerName, @"containerName",
+ [objectNames objectAtIndex:i], @"objectName",
+ [contentTypes objectAtIndex:i], @"contentType",
+ [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize",
+ blockHash, @"blockHash",
+ [filePaths objectAtIndex:i], @"filePath",
+ [hashesArrays objectAtIndex:i], @"hashes",
+ [NSNumber numberWithUnsignedInteger:10], @"iteration",
+ nil];
+ if (node.sharingAccount)
+ [userInfo setObject:node.sharingAccount forKey:@"sharingAccount"];
+ objectRequest.userInfo = userInfo;
[objectRequest startAsynchronous];
}
}
objectName:@".upload"
blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
forFile:[objectRequest.userInfo objectForKey:@"filePath"]
- missingBlockIndex:missingBlockIndex];
+ missingBlockIndex:missingBlockIndex
+ sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
newObjectRequest.delegate = self;
newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:);
newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:);
blockHash:[objectRequest.userInfo objectForKey:@"blockHash"]
forFile:[objectRequest.userInfo objectForKey:@"filePath"]
checkIfExists:NO
- hashes:&hashes];
+ hashes:&hashes
+ sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
newObjectRequest.delegate = self;
newObjectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
newObjectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
objectName:@".upload"
blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
forFile:[objectRequest.userInfo objectForKey:@"filePath"]
- missingBlockIndex:missingBlockIndex];
+ missingBlockIndex:missingBlockIndex
+ sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
newObjectRequest.delegate = self;
newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:);
newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:);
blockHash:(NSString *)blockHash
forFile:(NSString *)filePath
checkIfExists:(BOOL)ifExists
- hashes:(NSArray **)hashes;
+ 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;
+ missingHashesResponse:(NSString *)missingHashesResponse
+ sharingAccount:(NSString *)sharingAccount;
+ (ASIPithosObjectRequest *)updateObjectDataRequestWithContainerName:(NSString *)containerName
objectName:(NSString *)objectName
blockSize:(NSUInteger)blockSize
forFile:(NSString *)filePath
- missingBlockIndex:(NSUInteger)missingBlockIndex;
+ missingBlockIndex:(NSUInteger)missingBlockIndex
+ sharingAccount:(NSString *)sharingAccount;
+ (NSArray *)writeObjectDataRequestsWithContainerName:(NSString *)containerName
objectName:(NSString *)objectName
blockSize:(NSUInteger)blockSize
contentTypes:(NSMutableArray **)contentTypes
filePaths:(NSMutableArray **)filePaths
hashesArrays:(NSMutableArray **)hashesArrays
- directoryObjectRequests:(NSMutableArray **) directoryObjectRequests;
+ directoryObjectRequests:(NSMutableArray **) directoryObjectRequests
+ sharingAccount:(NSString *)sharingAccount;
+ (NSArray *)deleteObjectRequestsForSubdirWithContainerName:(NSString *)containerName objectName:(NSString *)objectName;
+ (NSUInteger)bytesOfFile:(NSString *)filePath;
+ (NSString *)contentTypeOfFile:(NSString *)filePath error:(NSError **)error;
+ (BOOL)objectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName
- error:(NSError **)error isDirectory:(BOOL *)isDirectory;
-+ (BOOL)proceedIfObjectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName;
+ error:(NSError **)error isDirectory:(BOOL *)isDirectory sharingAccount:(NSString *)sharingAccount;
++ (BOOL)proceedIfObjectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName
+ sharingAccount:(NSString *)sharingAccount;
+ (NSArray *)objectsWithContainerName:(NSString *)containerName objectNamePrefix:(NSString *)objectNamePrefix
delimiter:(NSString *)delimiter sharingAccount:(NSString *)sharingAccount;
+ (NSArray *)objectsForSubdirWithContainerName:(NSString *)containerName objectName:(NSString *)objectName
blockHash:(NSString *)blockHash
forFile:(NSString *)filePath
checkIfExists:(BOOL)ifExists
- hashes:(NSArray **)hashes {
- if (ifExists && ![self proceedIfObjectExistsAtContainerName:containerName objectName:objectName])
+ hashes:(NSArray **)hashes
+ sharingAccount:(NSString *)sharingAccount {
+ if (ifExists && ![self proceedIfObjectExistsAtContainerName:containerName objectName:objectName
+ sharingAccount:(NSString *)sharingAccount])
return nil;
if (*hashes == nil)
blockHash:blockHash
hashes:*hashes
bytes:bytes];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
return objectRequest;
}
blockSize:(NSUInteger)blockSize
forFile:(NSString *)filePath
hashes:(NSArray *)hashes
- missingHashesResponse:(NSString *)missingHashesResponse {
+ missingHashesResponse:(NSString *)missingHashesResponse
+ sharingAccount:(NSString *)sharingAccount {
NSIndexSet *missingBlocks = [self missingBlocksForHashes:hashes withMissingHashesResponse:missingHashesResponse];
NSFileManager *defaultManager = [NSFileManager defaultManager];
[tempFileHandle closeFile];
[fileHandle closeFile];
- return [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];
+ 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];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
+ return objectRequest;
}
+ (ASIPithosObjectRequest *)updateObjectDataRequestWithContainerName:(NSString *)containerName
objectName:(NSString *)objectName
blockSize:(NSUInteger)blockSize
forFile:(NSString *)filePath
- missingBlockIndex:(NSUInteger)missingBlockIndex {
+ missingBlockIndex:(NSUInteger)missingBlockIndex
+ sharingAccount:(NSString *)sharingAccount {
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];
[fileHandle seekToFileOffset:(missingBlockIndex *blockSize)];
NSData *blockData = [fileHandle readDataOfLength:blockSize];
[fileHandle closeFile];
- return [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];
+ 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];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
+ return objectRequest;
}
+ (NSArray *)writeObjectDataRequestsWithContainerName:(NSString *)containerName
contentTypes:(NSMutableArray **)contentTypes
filePaths:(NSMutableArray **)filePaths
hashesArrays:(NSMutableArray **)hashesArrays
- directoryObjectRequests:(NSMutableArray **) directoryObjectRequests {
- if (ifExists && ![self proceedIfObjectExistsAtContainerName:containerName objectName:objectName])
+ directoryObjectRequests:(NSMutableArray **) directoryObjectRequests
+ sharingAccount:(NSString *)sharingAccount {
+ if (ifExists && ![self proceedIfObjectExistsAtContainerName:containerName objectName:objectName sharingAccount:sharingAccount])
return nil;
NSFileManager *defaultManager = [NSFileManager defaultManager];
}
*directoryObjectRequests = [NSMutableArray arrayWithCapacity:[subPaths count]];
- [*directoryObjectRequests addObject:[ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName
- objectName:objectName
- eTag:nil
- contentType:@"application/directory"
- contentEncoding:nil
- contentDisposition:nil
- manifest:nil
- sharing:nil
- isPublic:ASIPithosObjectRequestPublicIgnore
- metadata:nil
- data:[NSData data]]];
-
+ ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName
+ objectName:objectName
+ eTag:nil
+ contentType:@"application/directory"
+ contentEncoding:nil
+ contentDisposition:nil
+ manifest:nil
+ sharing:nil
+ isPublic:ASIPithosObjectRequestPublicIgnore
+ metadata:nil
+ data:[NSData data]];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
+ [*directoryObjectRequests addObject:objectRequest];
NSMutableArray *objectRequests = [NSMutableArray arrayWithCapacity:[subPaths count]];
*objectNames = [NSMutableArray arrayWithCapacity:[subPaths count]];
contentType = @"application/octet-stream";
if (error)
NSLog(@"contentType detection error: %@", error);
- [objectRequests addObject:[ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName
- objectName:subObjectName
- contentType:contentType
- contentEncoding:nil
- contentDisposition:nil
- manifest:nil
- sharing:nil
- isPublic:ASIPithosObjectRequestPublicIgnore
- metadata:nil
- blockSize:blockSize
- blockHash:blockHash
- hashes:hashes
- bytes:bytes]];
+ objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName
+ objectName:subObjectName
+ contentType:contentType
+ contentEncoding:nil
+ contentDisposition:nil
+ manifest:nil
+ sharing:nil
+ isPublic:ASIPithosObjectRequestPublicIgnore
+ metadata:nil
+ blockSize:blockSize
+ blockHash:blockHash
+ hashes:hashes
+ bytes:bytes];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
+ [objectRequests addObject:objectRequest];
[*objectNames addObject:subObjectName];
[*contentTypes addObject:contentType];
[*filePaths addObject:filePath];
} else {
subObjectName = [objectName stringByAppendingPathComponent:objectNameSuffix];
- [*directoryObjectRequests addObject:[ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName
- objectName:subObjectName
- eTag:nil
- contentType:@"application/directory"
- contentEncoding:nil
- contentDisposition:nil
- manifest:nil
- sharing:nil
- isPublic:ASIPithosObjectRequestPublicIgnore
- metadata:nil
- data:[NSData data]]];
+ objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName
+ objectName:subObjectName
+ eTag:nil
+ contentType:@"application/directory"
+ contentEncoding:nil
+ contentDisposition:nil
+ manifest:nil
+ sharing:nil
+ isPublic:ASIPithosObjectRequestPublicIgnore
+ metadata:nil
+ data:[NSData data]];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
+ [*directoryObjectRequests addObject:objectRequest];
}
}
}
destinationObjectName:(NSString *)destinationObjectName
checkIfExists:(BOOL)ifExists
sharingAccount:(NSString *)sharingAccount {
- if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName])
+ if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName sharingAccount:nil])
return nil;
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest copyObjectDataRequestWithContainerName:containerName
destinationObjectName:(NSString *)destinationObjectName
checkIfExists:(BOOL)ifExists
sharingAccount:(NSString *)sharingAccount {
- if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName])
+ if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName sharingAccount:nil])
return nil;
NSArray *objects = [self objectsForSubdirWithContainerName:containerName objectName:objectName
destinationContainerName:(NSString *)destinationContainerName
destinationObjectName:(NSString *)destinationObjectName
checkIfExists:(BOOL)ifExists {
- if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName])
+ if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName sharingAccount:nil])
return nil;
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest moveObjectDataRequestWithContainerName:containerName
destinationContainerName:(NSString *)destinationContainerName
destinationObjectName:(NSString *)destinationObjectName
checkIfExists:(BOOL)ifExists {
- if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName])
+ if (ifExists && ![self proceedIfObjectExistsAtContainerName:destinationContainerName objectName:destinationObjectName sharingAccount:nil])
return nil;
NSArray *objects = [self objectsForSubdirWithContainerName:containerName objectName:objectName delimiter:nil sharingAccount:nil];
// 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
- error:(NSError **)error isDirectory:(BOOL *)isDirectory {
+ error:(NSError **)error isDirectory:(BOOL *)isDirectory
+ sharingAccount:(NSString *)sharingAccount {
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest objectMetadataRequestWithContainerName:containerName
objectName:objectName];
+ if (sharingAccount)
+ [objectRequest setRequestUserFromDefaultTo:sharingAccount];
[objectRequest startSynchronous];
*error = [objectRequest error];
if (*error) {
// Returns if the called should proceed, after an interactive check if an object exists
// at the given container/object path is performed
-+ (BOOL)proceedIfObjectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName {
++ (BOOL)proceedIfObjectExistsAtContainerName:(NSString *)containerName objectName:(NSString *)objectName
+ sharingAccount:(NSString *)sharingAccount {
NSError *error = nil;
BOOL isDirectory;
BOOL objectExists = [self objectExistsAtContainerName:containerName
objectName:objectName
error:&error
- isDirectory:&isDirectory];
+ isDirectory:&isDirectory
+ sharingAccount:sharingAccount];
if (error) {
return NO;
} else if (objectExists) {
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 (sharingAccount)
+ [alert setInformativeText:[NSString stringWithFormat:@"A directory with path '%@' in the container '%@' of user '%@' already exists, do you want to replace it?", objectName, containerName, sharingAccount]];
+ else
+ [alert setInformativeText:[NSString stringWithFormat:@"A directory with path '%@' in the container '%@' already exists, do you want to replace it?", objectName, containerName]];
} 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]];
+ if (sharingAccount)
+ [alert setInformativeText:[NSString stringWithFormat:@"An object with path '%@' in the container '%@' of user '%@' already exists, do you want to replace it?", objectName, containerName, sharingAccount]];
+ else
+ [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"];