From a905ab569ab092b7166060f964cc6846b520dfb4 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 25 Oct 2011 10:41:20 +0300 Subject: [PATCH] Local objects that are deleted in sync are not moved to trash anymore. Final feature isn't decided yet. --- pithos-macos/PithosSyncDaemon.m | 77 ++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/pithos-macos/PithosSyncDaemon.m b/pithos-macos/PithosSyncDaemon.m index eef38fa..d91e5d9 100644 --- a/pithos-macos/PithosSyncDaemon.m +++ b/pithos-macos/PithosSyncDaemon.m @@ -51,8 +51,11 @@ @interface PithosSyncDaemon (Private) - (NSString *)pithosStateFilePath; - (void)saveLocalState; + - (BOOL)moveToTempTrashFile:(NSString *)filePath; +- (void)emptyTempTrash; - (BOOL)findLocalCopyForObjectWithHash:(NSString *)hash forFile:(NSString *)filePath; + - (void)updateLocalStateWithObject:(ASIPithosObject *)object localFilePath:(NSString *)filePath; - (void)updateServerStateWithCurrentState:(PithosLocalObjectState *)currentState object:(ASIPithosObject *)object @@ -237,37 +240,13 @@ - (void)decreaseSyncOperationCount { @synchronized(self) { syncOperationCount--; - if (!syncOperationCount && !syncIncomplete) { - self.lastCompletedSync = [NSDate date]; - [activityFacility startAndEndActivityWithType:PithosActivityOther - message:[NSString stringWithFormat:@"Sync: Completed %@", lastCompletedSync]]; - // The sync cycle is completed and the final operation is to move the Trash Folder the contents of the Temp Trash - NSString *trashDirPath = self.tempTrashDirPath; - if (tempTrashDirPath) { - NSError *error = nil; - NSArray *subPaths = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:trashDirPath error:&error]; - if (error) { - [PithosUtilities fileActionFailedAlertWithTitle:@"Directory Contents Error" - message:[NSString stringWithFormat:@"Cannot get contents of directory at '%@'", containerDirectoryPath] - error:error]; - return; - } - if ([subPaths count]) { - NSMutableArray *subURLs = [NSMutableArray arrayWithCapacity:[subPaths count]]; - for (NSString *subPath in subPaths) { - [subURLs addObject:[NSURL fileURLWithPath:[trashDirPath stringByAppendingPathComponent:subPath]]]; - } - syncOperationCount = 1; - [[NSWorkspace sharedWorkspace] recycleURLs:subURLs completionHandler:^(NSDictionary *newURLs, NSError *error) { - if (error) { - [PithosUtilities fileActionFailedAlertWithTitle:@"Move to Trash Error" - message:@"Cannot move files to Trash" - error:error]; - } - syncOperationCount = 0; - }]; - } + if (!syncOperationCount) { + if (!syncIncomplete) { + self.lastCompletedSync = [NSDate date]; + [activityFacility startAndEndActivityWithType:PithosActivityOther + message:[NSString stringWithFormat:@"Sync: Completed %@", lastCompletedSync]]; } + [self emptyTempTrash]; } } } @@ -336,6 +315,44 @@ [queue addOperation:[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh]]; } +- (void)emptyTempTrash { + NSString *trashDirPath = self.tempTrashDirPath; + if (tempTrashDirPath) { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *error = nil; +// NSArray *subPaths = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:trashDirPath error:&error]; + NSArray *subPaths = [fileManager contentsOfDirectoryAtPath:trashDirPath error:&error]; + if (error) { + [PithosUtilities fileActionFailedAlertWithTitle:@"Directory Contents Error" + message:[NSString stringWithFormat:@"Cannot get contents of directory at '%@'", containerDirectoryPath] + error:error]; + return; + } + if ([subPaths count]) { +// NSMutableArray *subURLs = [NSMutableArray arrayWithCapacity:[subPaths count]]; +// for (NSString *subPath in subPaths) { +// [subURLs addObject:[NSURL fileURLWithPath:[trashDirPath stringByAppendingPathComponent:subPath]]]; +// } +// syncOperationCount = 1; +// [[NSWorkspace sharedWorkspace] recycleURLs:subURLs completionHandler:^(NSDictionary *newURLs, NSError *error) { +// if (error) { +// [PithosUtilities fileActionFailedAlertWithTitle:@"Move to Trash Error" +// message:@"Cannot move files to Trash" +// error:error]; +// } +// syncOperationCount = 0; +// }]; + for (NSString *subPath in subPaths) { + error = nil; + if (![fileManager removeItemAtPath:subPath error:&error] || error) + [PithosUtilities fileActionFailedAlertWithTitle:@"Remove File Error" + message:[NSString stringWithFormat:@"Cannot remove file at '%@'", subPath] + error:error]; + } + } + } +} + - (BOOL)moveToTempTrashFile:(NSString *)filePath { NSString *trashDirPath = self.tempTrashDirPath; if (!tempTrashDirPath) -- 1.7.10.4