From 6456bf24e25fd17fbe6f62f2d8847ce9e0865ddf Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Fri, 18 Nov 2011 13:33:45 +0200 Subject: [PATCH] For local updates from remote objects, a check is made if the remote object still exists, and the appropriate action is taken. --- pithos-macos/PithosSyncDaemon.m | 45 +++++++++++++++++++++++++++++++++++---- pithos-macos/PithosUtilities.m | 2 +- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/pithos-macos/PithosSyncDaemon.m b/pithos-macos/PithosSyncDaemon.m index f80e522..9fcc61c 100644 --- a/pithos-macos/PithosSyncDaemon.m +++ b/pithos-macos/PithosSyncDaemon.m @@ -634,8 +634,20 @@ BOOL isDirectory; BOOL fileExists = [fileManager fileExistsAtPath:filePath isDirectory:&isDirectory]; PithosLocalObjectState *storedState = [storedLocalObjectStates objectForKey:object.name]; + // Remote updated info + NSError *remoteError; + BOOL remoteIsDirectory; + BOOL remoteObjectExists = [PithosUtilities objectExistsAtContainerName:containerName + objectName:object.name + error:&remoteError + isDirectory:&remoteIsDirectory + sharingAccount:nil]; if (!object || !object.hash) { // Delete local object + if (remoteObjectExists) { + // Remote object created in the meantime, just mark the sync cycle as incomplete, but do delete the local object + syncIncomplete = YES; + } NSLog(@"Sync::delete local object: %@", filePath); if (!fileExists || [self moveToTempTrashFile:filePath]) { [self startAndEndActivityWithType:PithosActivityOther @@ -645,6 +657,11 @@ } } else if ([PithosUtilities isContentTypeDirectory:object.contentType]) { // Create local directory object + if (!remoteObjectExists || !remoteIsDirectory) { + // Remote directory object deleted or changed to a file object in the meantime, mark the sync cycle as incomplete and skip + syncIncomplete = YES; + return; + } NSLog(@"Sync::create local directory object: %@", filePath); BOOL directoryCreated = NO; if (!fileExists || (!isDirectory && [self moveToTempTrashFile:filePath])) { @@ -668,6 +685,11 @@ message:[NSString stringWithFormat:@"Sync: Creating directory '%@' locally (finished)", object.name]]; } else if (object.bytes == 0) { // Create local object with zero length + if (!remoteObjectExists || remoteIsDirectory) { + // Remote file object deleted or changed to a directory object in the meantime, mark the sync cycle as incomplete and skip + syncIncomplete = YES; + return; + } NSLog(@"Sync::create local zero length object: %@", filePath); BOOL fileCreated = NO; if (!fileExists || ((isDirectory || [PithosUtilities bytesOfFile:filePath]) && [self moveToTempTrashFile:filePath])) { @@ -692,6 +714,11 @@ message:[NSString stringWithFormat:@"Sync: Downloading '%@' (100%%)", object.name]]; } else if (storedState.filePath == nil) { // Create new local object + if (!remoteObjectExists || remoteIsDirectory) { + // Remote file object deleted or changed to a directory object in the meantime, mark the sync cycle as incomplete and skip + syncIncomplete = YES; + return; + } // Check first if a local copy exists if ([self findLocalCopyForObjectWithHash:object.hash forFile:filePath]) { [self startAndEndActivityWithType:PithosActivityOther @@ -736,6 +763,11 @@ } } else { // Resume local object download + if (!remoteObjectExists || remoteIsDirectory) { + // Remote file object deleted or changed to a directory object in the meantime, mark the sync cycle as incomplete and skip + syncIncomplete = YES; + return; + } // Check first if a local copy exists if ([self findLocalCopyForObjectWithHash:object.hash forFile:filePath]) { [self startAndEndActivityWithType:PithosActivityOther @@ -826,13 +858,18 @@ // Local object created in the meantime, just mark the sync cycle as incomplete, but do delete the server object syncIncomplete = YES; } - NSString *safeObjectName = [PithosUtilities safeObjectNameForContainerName:@"trash" - objectName:object.name]; - if (safeObjectName) { + NSString *safeName; + if ([PithosUtilities isContentTypeDirectory:object.contentType]) + safeName = [PithosUtilities safeSubdirNameForContainerName:@"trash" + subdirName:object.name]; + else + safeName = [PithosUtilities safeObjectNameForContainerName:@"trash" + objectName:object.name]; + if (safeName) { ASIPithosObjectRequest *objectRequest = [PithosUtilities moveObjectRequestWithContainerName:containerName objectName:object.name destinationContainerName:@"trash" - destinationObjectName:safeObjectName + destinationObjectName:safeName checkIfExists:NO]; if (objectRequest) { objectRequest.delegate = self; diff --git a/pithos-macos/PithosUtilities.m b/pithos-macos/PithosUtilities.m index ac77ffe..c5fc3cc 100644 --- a/pithos-macos/PithosUtilities.m +++ b/pithos-macos/PithosUtilities.m @@ -872,7 +872,7 @@ return NO; } -// Returns if the called should proceed, after an interactive check if an object exists +// Returns if the caller 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 sharingAccount:(NSString *)sharingAccount { -- 1.7.10.4