@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
- (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];
}
}
}
[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)