Skip to content

Commit cc2ec93

Browse files
Add --warn-no-exec option to log a warning instead of throwing an exception
1 parent 9dca8a9 commit cc2ec93

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/main/java/com/glencoesoftware/bioformats2raw/Converter.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public class Converter implements Callable<Integer> {
128128
private volatile Path inputPath;
129129
private volatile String outputLocation;
130130

131+
private volatile boolean warnNoExec = false;
132+
131133
private Map<String, String> outputOptions;
132134
private volatile Integer pyramidResolutions;
133135
private volatile List<Integer> seriesList;
@@ -409,6 +411,23 @@ public void setProgressBars(boolean useProgressBars) {
409411
progressBars = useProgressBars;
410412
}
411413

414+
/**
415+
* Configure whether to warn instead of throwing an exception
416+
* if files created in the temporary directory
417+
* ("java.io.tmpdir" system property) will not be executable.
418+
*
419+
* @param warnOnly true if a warning should be logged instead of an exception
420+
*/
421+
@Option(
422+
names = {"--warn-no-exec"},
423+
description = "Warn instead of throwing an exception if " +
424+
"java.io.tmpdir is not executable",
425+
defaultValue = "false"
426+
)
427+
public void setWarnOnNoExec(boolean warnOnly) {
428+
warnNoExec = warnOnly;
429+
}
430+
412431
/**
413432
* Configure whether to print version information and exit
414433
* without converting.
@@ -944,6 +963,14 @@ public boolean getProgressBars() {
944963
return progressBars;
945964
}
946965

966+
/**
967+
* @return true if a warning is logged instead of an exception when the tmp
968+
* directory is noexec
969+
*/
970+
public boolean getWarnNoExec() {
971+
return warnNoExec;
972+
}
973+
947974
/**
948975
* @return true if only version info is displayed
949976
*/
@@ -1186,8 +1213,14 @@ public Integer call() throws Exception {
11861213
// the file will not actually be executable
11871214
boolean success = tmpdirCheck.setExecutable(true);
11881215
if (!success || !tmpdirCheck.canExecute()) {
1189-
throw new RuntimeException(System.getProperty("java.io.tmpdir") +
1190-
" is noexec; fix it or specify a different java.io.tmpdir");
1216+
String msg = System.getProperty("java.io.tmpdir") +
1217+
" is noexec; fix it or specify a different java.io.tmpdir";
1218+
if (getWarnNoExec()) {
1219+
LOGGER.warn(msg);
1220+
}
1221+
else {
1222+
throw new RuntimeException(msg);
1223+
}
11911224
}
11921225
tmpdirCheck.delete();
11931226

0 commit comments

Comments
 (0)