diff --git a/BlueLocalization/Source/Framework/Documents/Files/BLDocumentFileWrapper.m b/BlueLocalization/Source/Framework/Documents/Files/BLDocumentFileWrapper.m index 7a68c90..f41fae9 100644 --- a/BlueLocalization/Source/Framework/Documents/Files/BLDocumentFileWrapper.m +++ b/BlueLocalization/Source/Framework/Documents/Files/BLDocumentFileWrapper.m @@ -60,20 +60,30 @@ - (NSString *)temporaryPath { #pragma mark - Reading - (NSFileWrapper *)decompressedFileWrapperFromPath:(NSString *)path { + // This need to _replace_ the item at `path`, because that's where a Save operation will write an updated database back to! NSString *tmpPath = [self temporaryPath]; tmpPath = [tmpPath stringByAppendingPathComponent:[path lastPathComponent]]; + [[NSFileManager defaultManager] removeItemAtPath:tmpPath error:NULL]; // remove previously existing item so that copy operation won't fail + [[NSFileManager defaultManager] copyItemAtPath:path toPath:tmpPath error:NULL]; NSString *outPath = nil; if ([[NSFileManager defaultManager] decompressFileAtPath:tmpPath usedCompression:NULL resultPath:&outPath keepOriginal:NO]) { - NSFileWrapper *wrapper = [[NSFileWrapper alloc] initWithURL:[NSURL fileURLWithPath:outPath] options:0 error:nil]; - [[NSFileManager defaultManager] removeItemAtPath:outPath error:NULL]; - + // This operation has replaced the compressed file with a directory in its place. We now move that back into the original location at `path`. + tmpPath = [tmpPath stringByAppendingString:@".old"]; + if (![[NSFileManager defaultManager] moveItemAtPath:path toPath:tmpPath error:NULL]) { + return nil; + } + if (![[NSFileManager defaultManager] moveItemAtPath:outPath toPath:path error:NULL]) { + [[NSFileManager defaultManager] moveItemAtPath:tmpPath toPath:path error:NULL]; // let's try to restore the original + return nil; + } + NSFileWrapper *wrapper = [[NSFileWrapper alloc] initWithURL:[NSURL fileURLWithPath:path] options:0 error:nil]; return wrapper; } else { - [[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath:tmpPath error:NULL]; return nil; } } diff --git a/BlueLocalization/Source/Framework/Model/Base/BLObjectProxy.m b/BlueLocalization/Source/Framework/Model/Base/BLObjectProxy.m index 34dfbc7..4579dd1 100644 --- a/BlueLocalization/Source/Framework/Model/Base/BLObjectProxy.m +++ b/BlueLocalization/Source/Framework/Model/Base/BLObjectProxy.m @@ -138,7 +138,7 @@ - (void)forwardInvocation:(NSInvocation *)invocation { } else { dispatch_sync(dispatch_get_main_queue(), ^{ - [invocation invokeWithTarget:_object]; + [invocation invokeWithTarget:self->_object]; }); } @@ -158,7 +158,7 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel { else { __block NSMethodSignature *sig; dispatch_sync(dispatch_get_main_queue(), ^{ - sig = [_class instanceMethodSignatureForSelector:sel]; + sig = [self->_class instanceMethodSignatureForSelector:sel]; }); return sig; }