Skip to content

Commit

Permalink
Fixes for self patch
Browse files Browse the repository at this point in the history
Deleting entire temporary directory. Also removing redundant unlink - it was causing problems because the unlinked app was getting swapped into the temporary directory.
  • Loading branch information
colincornaby committed Jul 1, 2024
1 parent ab6d0b4 commit ea2c595
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ @interface PLSPatcher ()
@property NSTimer* networkPumpTimer;
@property Patcher cppPatcher;
@property NSURL* updatedClientURL;
@property NSURL* temporaryDirectory;
@end

@implementation PLSPatcher
Expand Down Expand Up @@ -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;

Expand All @@ -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];
Expand Down Expand Up @@ -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();
Expand All @@ -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];
}

Expand Down

0 comments on commit ea2c595

Please sign in to comment.