From dd6852d7955a9b93de7436bfec5ed983c5b862c4 Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Mon, 6 May 2024 15:49:10 +0200 Subject: [PATCH 1/2] Fixes a warning about accessing `self` inside a block. --- BlueLocalization/Source/Framework/Model/Base/BLObjectProxy.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } From 51ff6dbd4128fd1fbd4c40dc6b19e44868094f3a Mon Sep 17 00:00:00 2001 From: Thomas Tempelmann Date: Mon, 6 May 2024 15:50:34 +0200 Subject: [PATCH 2/2] Fixes 2 bugs around loading the legacy compressed .ldb files: It deleted the decompressed dir before it could be read, and it left the expanded dir in the tmp location but needs to replace the original for Save to work later). --- .../Documents/Files/BLDocumentFileWrapper.m | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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; } }