From ea2c595273a621a8219254ec868f8b4d8dcc0587 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sun, 30 Jun 2024 22:45:37 -0700 Subject: [PATCH] Fixes for self patch Deleting entire temporary directory. Also removing redundant unlink - it was causing problems because the unlinked app was getting swapped into the temporary directory. --- .../Apps/plClient/Mac-Cocoa/PLSPatcher.mm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm index 5ce38d11b5..812582fbf7 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm @@ -75,6 +75,7 @@ @interface PLSPatcher () @property NSTimer* networkPumpTimer; @property Patcher cppPatcher; @property NSURL* updatedClientURL; +@property NSURL* temporaryDirectory; @end @implementation PLSPatcher @@ -118,7 +119,7 @@ - (void)start - (NSURL *)completeSelfPatch:(NSError **)error; { NSString* destinationPath = [NSString stringWithSTString:plManifest::PatcherExecutable().AsString()]; - NSURL* destinationURL = [NSURL fileURLWithPath:[NSString stringWithSTString:plManifest::PatcherExecutable().AsString()]]; + NSURL* destinationURL = [NSURL fileURLWithPath:destinationPath]; NSError* errorInScope; @@ -139,7 +140,9 @@ - (NSURL *)completeSelfPatch:(NSError **)error; if (swapSucceeded) { // delete the old version - this is very likely us // we want to terminate after. Our bundle will no longer be valid. - [NSFileManager.defaultManager removeItemAtURL:self.updatedClientURL error:&errorInScope]; + if (self.temporaryDirectory) { + [NSFileManager.defaultManager removeItemAtURL:self.temporaryDirectory error:&errorInScope]; + } } else { // abort and return an error errorInScope = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]; @@ -231,7 +234,7 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) la_ssize_t r; /* Select which attributes we want to restore. */ - flags = ARCHIVE_EXTRACT_TIME; + flags = ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM; struct archive *a = archive_read_new(); struct archive *ext = archive_write_disk_new(); @@ -256,13 +259,11 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) return; } - plFileSystem::Unlink(plManifest::PatcherExecutable()); - NSError *error; - NSURL *tempDirectory = [NSFileManager.defaultManager URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:[NSURL fileURLWithPath:NSFileManager.defaultManager.currentDirectoryPath] create:YES error:&error]; + patcher.temporaryDirectory = [NSFileManager.defaultManager URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:[NSURL fileURLWithPath:NSFileManager.defaultManager.currentDirectoryPath] create:YES error:&error]; NSURL *outputURL; - if (tempDirectory) { - outputURL = [tempDirectory URLByAppendingPathComponent:[NSString stringWithSTString:plManifest::PatcherExecutable().GetFileName()]]; + if (patcher.temporaryDirectory) { + outputURL = [patcher.temporaryDirectory URLByAppendingPathComponent:[NSString stringWithSTString:plManifest::PatcherExecutable().GetFileName()]]; [NSFileManager.defaultManager createDirectoryAtURL:outputURL withIntermediateDirectories:false attributes:nil error:&error]; }