Skip to content

Commit 65e576e

Browse files
committed
Better error checking in app delegate, hopefully last of style feedback in review.
1 parent 0c9a26c commit 65e576e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Switch/SWAppDelegate.m

+10-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ - (void)relaunch:(id)sender;
4040
NSString *processID = [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]];
4141

4242
NSError *error = NULL;
43-
[[NSFileManager defaultManager] removeItemAtPath:launcherTarget error:&error];
44-
Check(error);
45-
[[NSFileManager defaultManager] copyItemAtPath:launcherSource toPath:launcherTarget error:&error];
46-
Check(error);
43+
BOOL success = YES;
44+
45+
success = [[NSFileManager defaultManager] removeItemAtPath:launcherTarget error:&error];
46+
if (!success) {
47+
// Code 4: "The operation couldn’t be completed. No such file or directory"
48+
Check(error.code == 4);
49+
}
50+
51+
success = [[NSFileManager defaultManager] copyItemAtPath:launcherSource toPath:launcherTarget error:&error];
52+
Check(success);
4753

4854
[NSTask launchedTaskWithLaunchPath:launcherTarget arguments:@[appPath, processID]];
4955
[NSApp terminate:sender];

relaunch/SWTerminationListener.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@interface SWTerminationListener : NSObject
1818

19-
- (id) initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid;
20-
- (void) relaunch;
19+
- (id)initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid;
20+
- (void)relaunch;
2121

2222
@end

0 commit comments

Comments
 (0)