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
}
} 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])) {
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])) {
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
}
} 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
// 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;