From 3f92820cf45b2d79482834d52878d9064a62b403 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 3 Feb 2024 18:17:25 -0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: dgelessus --- .../Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.h | 2 +- .../Apps/plClient/Mac-Cocoa/PLSPatcher.mm | 17 ++++------------- .../Plasma/FeatureLib/pfPatcher/pfPatcher.cpp | 1 - 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.h b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.h index 08cf3d6770..fb6c956512 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.h +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.h @@ -60,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN @property(weak) id delegate; @property(readonly) BOOL selfPatched; -- (NSURL *)completeSelfPatch; +- (NSURL*)completeSelfPatch; - (void)start; @end diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm index e4249b4afd..ac506f1145 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm @@ -117,30 +117,21 @@ - (void)start - (NSURL *)completeSelfPatch { NSString* destinationPath = [NSString stringWithSTString:plManifest::PatcherExecutable().AsString()]; - NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithSTString:plManifest::PatcherExecutable().AsString()]]; + NSURL* destinationURL = [NSURL fileURLWithPath:[NSString stringWithSTString:plManifest::PatcherExecutable().AsString()]]; if ([NSFileManager.defaultManager fileExistsAtPath:destinationPath]) { // need to swap - - char originalPath[PATH_MAX] = {0}; - [self.updatedClientURL.path getFileSystemRepresentation:originalPath maxLength:sizeof(originalPath)]; - - char newPath[PATH_MAX] = {0}; - [destinationURL.path getFileSystemRepresentation:newPath maxLength:sizeof(newPath)]; - - renamex_np(newPath, originalPath, RENAME_SWAP); + renamex_np(destinationURL.path.fileSystemRepresentation, self.updatedClientURL.path.fileSystemRepresentation, RENAME_SWAP); // 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:nil]; - return destinationURL; } else { // no executable already present! Just move things into place. [NSFileManager.defaultManager moveItemAtURL:self.updatedClientURL toURL:destinationURL error:nil]; - return destinationURL; } - return nil; + return destinationURL; } void Patcher::IOnDownloadBegin(const plFileName& file) @@ -227,7 +218,7 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) [NSFileManager.defaultManager createDirectoryAtURL:outputURL withIntermediateDirectories:false attributes:nil error:nil]; ST::string outputPath = [outputURL.path STString]; - for (;;) { + while (true) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; diff --git a/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp b/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp index f44d5a2534..20702a0dfd 100644 --- a/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp +++ b/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp @@ -574,7 +574,6 @@ void pfPatcherWorker::IHashFile(pfPatcherQueuedFile& file) // Check to see if ours matches plFileName clientPathForComparison = file.fClientPath; if (file.fFlags & kBundle) { - bool whitelistBundle = true; if (fFindBundleExe) { clientPathForComparison = fFindBundleExe(clientPathForComparison); }