- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- if (operation.isCancelled) {
- [pool drain];
- return;
- }
- NSString *destinationObjectName = [[node.pithosObject.name stringByDeletingLastPathComponent] stringByAppendingPathComponent:newName];
- if ([newName hasSuffix:@"/"])
- destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
- NSError *error = nil;
- BOOL isDirectory;
- if ([PithosUtilities objectExistsAtPithos:pithos
- containerName:node.pithosContainer.name
- objectName:destinationObjectName
- error:&error
- isDirectory:&isDirectory
- sharingAccount:nil]) {
- dispatch_async(dispatch_get_main_queue(), ^{
- 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]];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- });
- [pool drain];
- return;
- } else if (error) {
- [pool drain];
- return;
- }
- if (operation.isCancelled) {
- [pool drain];
- return;
- }
- ASIPithosObjectRequest *objectRequest = [PithosUtilities moveObjectRequestWithPithos:pithos
- containerName:node.pithosContainer.name
- objectName:node.pithosObject.name
- destinationContainerName:node.pithosContainer.name
- destinationObjectName:destinationObjectName
- checkIfExists:NO];
- if (!operation.isCancelled && objectRequest) {
- objectRequest.delegate = self;
- objectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:);
- objectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:);
- NSString *messagePrefix = [NSString stringWithFormat:@"Moving '%@/%@' to '%@/%@'",
- [objectRequest.userInfo objectForKey:@"sourceContainerName"],
- [objectRequest.userInfo objectForKey:@"sourceObjectName"],
- [objectRequest.userInfo objectForKey:@"destinationContainerName"],
- [objectRequest.userInfo objectForKey:@"destinationObjectName"]];
- PithosActivity *activity = [activityFacility startActivityWithType:PithosActivityMove
- message:messagePrefix];
- [(NSMutableDictionary *)(objectRequest.userInfo) addEntriesFromDictionary:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [NSArray arrayWithObject:node.parent], @"forceRefreshNodes",
- [NSNumber numberWithBool:YES], @"refresh",
- activity, @"activity",
- [messagePrefix stringByAppendingString:@" (stopped)"], @"stoppedActivityMessage",
- [messagePrefix stringByAppendingString:@" (failed)"], @"failedActivityMessage",
- [messagePrefix stringByAppendingString:@" (finished)"], @"finishedActivityMessage",
- [NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority",
- [NSNumber numberWithUnsignedInteger:10], @"retries",
- NSStringFromSelector(@selector(moveFinished:)), @"didFinishSelector",
- NSStringFromSelector(@selector(requestFailed:)), @"didFailSelector",
- moveNetworkQueue, @"networkQueue",
- @"move", @"operationType",
- nil]];
- [moveNetworkQueue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]];
- }
- [pool drain];
- }];
- [moveQueue addOperation:operation];
- } else if ([node class] == [PithosSubdirNode class]) {
- if (firstSlashRange.length == 1)
- return;
- // Operation: Rename (move) a subdir node and its descendants
- // The resulting ASIPithosObjectRequests are chained through dependencies
- __block NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- if (operation.isCancelled) {
- [pool drain];
- return;
- }
- NSString *destinationObjectName = [[node.pithosObject.name stringByDeletingLastPathComponent] stringByAppendingPathComponent:newName];
- NSError *error = nil;
- BOOL isDirectory;
- if ([PithosUtilities objectExistsAtPithos:pithos
- containerName:node.pithosContainer.name
- objectName:destinationObjectName
- error:&error
- isDirectory:&isDirectory
- sharingAccount:nil]) {
- dispatch_async(dispatch_get_main_queue(), ^{
- 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]];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- });
- [pool drain];
- return;
- } else if (error) {
- [pool drain];
- return;
- }
- if (operation.isCancelled) {
- [pool drain];
- return;
- }
- if (node.pithosObject.subdir)
- destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
- NSArray *objectRequests = [PithosUtilities moveObjectRequestsForSubdirWithPithos:pithos
- containerName:node.pithosContainer.name
- objectName:node.pithosObject.name
- destinationContainerName:node.pithosContainer.name
- destinationObjectName:destinationObjectName
- checkIfExists:NO];
- if (!operation.isCancelled && objectRequests) {
- ASIPithosObjectRequest *previousObjectRequest = nil;
- for (ASIPithosObjectRequest *objectRequest in objectRequests) {
- if (operation.isCancelled) {
- [pool drain];
- return;
- }
+ @autoreleasepool {
+ if (operation.isCancelled)
+ return;
+ NSString *destinationObjectName = [[node.pithosObject.name stringByDeletingLastPathComponent] stringByAppendingPathComponent:newName];
+ if ([newName hasSuffix:@"/"])
+ destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+ NSError *error = nil;
+ BOOL isDirectory;
+ if ([PithosUtilities objectExistsAtPithos:pithos
+ containerName:node.pithosContainer.name
+ objectName:destinationObjectName
+ error:&error
+ isDirectory:&isDirectory
+ sharingAccount:nil]) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:@"Name Taken"];
+ [alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
+ [alert addButtonWithTitle:@"OK"];
+ [alert runModal];
+ });
+ return;
+ } else if (error) {
+ return;
+ }
+ if (operation.isCancelled)
+ return;
+ ASIPithosObjectRequest *objectRequest = [PithosUtilities moveObjectRequestWithPithos:pithos
+ containerName:node.pithosContainer.name
+ objectName:node.pithosObject.name
+ destinationContainerName:node.pithosContainer.name
+ destinationObjectName:destinationObjectName
+ checkIfExists:NO];
+ if (!operation.isCancelled && objectRequest) {