Skip to content

Commit 6446eef

Browse files
authored
Fix DaemonProcess launch uncaught exception when the executable path is invalid/non-executable (#243)
* Fallback to default executable path of DaemonProcess path is invalid/non-executable; log path when launching * Fix logging typos * Comment why checking the executable is necessary * Normalize indentation to follow file's convention --------- Co-authored-by: Esaú García Sánchez-Torija <[email protected]>
1 parent 805dffe commit 6446eef

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

syncthing/DaemonProcess.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let MaxKeepLogLines = 200
5555
}
5656

5757
private func launchSync() {
58-
NSLog("Launching Syncthing daemon")
58+
NSLog("Launching Syncthing daemon: \(path)")
5959
shouldTerminate = false
6060

6161
// Since release v1.7.0-1 we don't allow Syncthing daemon to update by itself

syncthing/STApplication.m

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,25 @@ - (void)applicationLoadConfiguration {
7272
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
7373

7474
_executable = self.arguments = [defaults stringForKey:@"Executable"];
75-
if (!_executable) {
76-
_executable = [NSString stringWithFormat:@"%@/%@",
75+
76+
// Check that the excutable is valid (not null, exists and is executable)
77+
// If it's not, nullify it so that it will be set to the default value
78+
if (_executable) {
79+
NSFileManager *fileManager = [NSFileManager defaultManager];
80+
if (![fileManager fileExistsAtPath:_executable]) {
81+
NSLog(@"Resetting Syncthing daemon executable path because it doesn't exist: (%@)", _executable);
82+
_executable = nil;
83+
} else if (![fileManager isExecutableFileAtPath:_executable]) {
84+
NSLog(@"Resetting Syncthing daemon executable path because it's non-executable: (%@)", _executable);
85+
_executable = nil;
86+
}
87+
}
88+
89+
if (!_executable) {
90+
_executable = [NSString stringWithFormat:@"%@/%@",
7791
[[NSBundle mainBundle] resourcePath],
7892
@"syncthing/syncthing"];
79-
}
93+
}
8094

8195
_syncthing.URI = [defaults stringForKey:@"URI"];
8296
_syncthing.ApiKey = [defaults stringForKey:@"ApiKey"];

0 commit comments

Comments
 (0)