Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: dgelessus <dgelessus@users.noreply.github.com>
  • Loading branch information
colincornaby and dgelessus authored Feb 4, 2024
1 parent 8d6f470 commit 3f92820
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(weak) id<PLSPatcherDelegate> delegate;
@property(readonly) BOOL selfPatched;

- (NSURL *)completeSelfPatch;
- (NSURL*)completeSelfPatch;
- (void)start;

@end
Expand Down
17 changes: 4 additions & 13 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3f92820

Please sign in to comment.