Skip to content

Commit 5301a57

Browse files
committed
Set executable bit in a less fragile way
On my Ubuntu 24.04 system, I was seeing: [ERROR] java.io.IOException: Cannot run program "chmod": error=13, Permission denied at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089) at java.base/java.lang.Runtime.exec(Runtime.java:681) at java.base/java.lang.Runtime.exec(Runtime.java:530) at net.imagej.updater.Installer.verify(Installer.java:389) at net.imagej.updater.Installer$VerifyFiles.itemDone(Installer.java:333) at net.imagej.updater.util.AbstractProgressable.itemDone(AbstractProgressable.java:87) at net.imagej.updater.util.Downloader.download(Downloader.java:130) at net.imagej.updater.util.Downloader.start(Downloader.java:90) at net.imagej.updater.Installer.start(Installer.java:217) at net.imagej.ui.swing.updater.UpdaterFrame.install(UpdaterFrame.java:596) at net.imagej.ui.swing.updater.UpdaterFrame$5.run(UpdaterFrame.java:534) Caused by: java.io.IOException: error=13, Permission denied at java.base/java.lang.ProcessImpl.forkAndExec(Native Method) at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:295) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:225) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126) ... 11 more Why? I have no idea. But using the setExecutable method instead works.
1 parent bcdbc37 commit 5301a57

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/main/java/net/imagej/updater/CommandLine.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,8 @@ public void download(final FileObject file) {
489489
new Downloader(progress).start(new OneFile(file));
490490
if (file.executable && !Platforms.isWindows(files.platform())) {
491491
try {
492-
Runtime.getRuntime().exec(
493-
new String[] { "chmod", "0755",
494-
files.prefix(file.filename).getPath() });
492+
// Use Java's native file permissions API instead of spawning chmod process
493+
files.prefix(file.filename).setExecutable(true, false);
495494
} catch (final Exception e) {
496495
e.printStackTrace();
497496
throw die("Could not mark " + file.filename

src/main/java/net/imagej/updater/Installer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,8 @@ public void verify(final Download download) {
385385
file.setStatus(FileObject.Status.INSTALLED);
386386

387387
if (file.executable && !Platforms.isWindows(files.platform())) try {
388-
Runtime.getRuntime()
389-
.exec(
390-
new String[] { "chmod", "0755",
391-
download.destination.getAbsolutePath() });
388+
// Use Java's native file permissions API instead of spawning chmod process
389+
download.destination.setExecutable(true, false);
392390
}
393391
catch (final Exception e) {
394392
files.log.error(e);

0 commit comments

Comments
 (0)