Skip to content

Commit

Permalink
Add --warn-no-exec option to log a warning instead of throwing an e…
Browse files Browse the repository at this point in the history
…xception
  • Loading branch information
melissalinkert committed Jul 15, 2024
1 parent 9dca8a9 commit cc2ec93
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public class Converter implements Callable<Integer> {
private volatile Path inputPath;
private volatile String outputLocation;

private volatile boolean warnNoExec = false;

private Map<String, String> outputOptions;
private volatile Integer pyramidResolutions;
private volatile List<Integer> seriesList;
Expand Down Expand Up @@ -409,6 +411,23 @@ public void setProgressBars(boolean useProgressBars) {
progressBars = useProgressBars;
}

/**
* Configure whether to warn instead of throwing an exception
* if files created in the temporary directory
* ("java.io.tmpdir" system property) will not be executable.
*
* @param warnOnly true if a warning should be logged instead of an exception
*/
@Option(
names = {"--warn-no-exec"},
description = "Warn instead of throwing an exception if " +
"java.io.tmpdir is not executable",
defaultValue = "false"
)
public void setWarnOnNoExec(boolean warnOnly) {
warnNoExec = warnOnly;
}

/**
* Configure whether to print version information and exit
* without converting.
Expand Down Expand Up @@ -944,6 +963,14 @@ public boolean getProgressBars() {
return progressBars;
}

/**
* @return true if a warning is logged instead of an exception when the tmp
* directory is noexec
*/
public boolean getWarnNoExec() {
return warnNoExec;
}

/**
* @return true if only version info is displayed
*/
Expand Down Expand Up @@ -1186,8 +1213,14 @@ public Integer call() throws Exception {
// the file will not actually be executable
boolean success = tmpdirCheck.setExecutable(true);
if (!success || !tmpdirCheck.canExecute()) {
throw new RuntimeException(System.getProperty("java.io.tmpdir") +
" is noexec; fix it or specify a different java.io.tmpdir");
String msg = System.getProperty("java.io.tmpdir") +
" is noexec; fix it or specify a different java.io.tmpdir";
if (getWarnNoExec()) {
LOGGER.warn(msg);
}
else {
throw new RuntimeException(msg);
}
}
tmpdirCheck.delete();

Expand Down

0 comments on commit cc2ec93

Please sign in to comment.