Skip to content

Commit

Permalink
fix in CLI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmoho committed Oct 12, 2024
1 parent a0934bf commit 6692356
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ private void validateIOParameters() throws ParametersException {
throw new ParametersException(format(MESSAGES.getString("READ_FILE_ERROR"), input), parameters);
}

// Ensure the output directory or file's parent directory exists
SBMLFileUtils.checkCreateOutDir(output);

// If the input is a directory but the output is not, exit with error
if (input.isDirectory() && !output.isDirectory()) {
throw new ParametersException(format(MESSAGES.getString("WRITE_DIR_TO_FILE_ERROR"),
Expand All @@ -232,8 +235,6 @@ private void validateIOParameters() throws ParametersException {
parameters);
}

// Ensure the output directory or file's parent directory exists
SBMLFileUtils.checkCreateOutDir(output);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,25 @@ public static boolean isDirectory(File file) {
*/
public static void checkCreateOutDir(File output) {
logger.debug(format(MESSAGES.getString("OUTPUT_FILE_DESC"), isDirectory(output) ? "directory" : "file"));
// ModelPolisher.isDirectory() checks if output location contains ., if so it is assumed to be a file
// output is directory
if (isDirectory(output) && !output.exists()) {
logger.debug(format(MESSAGES.getString("CREATING_DIRECTORY"), output.getAbsolutePath()));
if (!output.mkdirs()) {
// TODO: grace
throw new RuntimeException(format(MESSAGES.getString("DIRECTORY_CREATION_FAILED"), output.getAbsolutePath()));
}
}
// output is a file
else {
// check if directory of outfile exist and create if required
if (!output.getParentFile().exists()) {
logger.debug(format(MESSAGES.getString("CREATING_DIRECTORY"), output.getParentFile().getAbsolutePath()));
if (!output.getParentFile().mkdirs()) {
if (!output.exists()) {
// ModelPolisher.isDirectory() checks if output location contains ., if so it is assumed to be a file
// output is directory
if (isDirectory(output)) {
logger.debug(format(MESSAGES.getString("CREATING_DIRECTORY"), output.getAbsolutePath()));
if (!output.mkdirs()) {
// TODO: grace
throw new RuntimeException(format(MESSAGES.getString("DIRECTORY_CREATION_FAILED"), output.getParentFile().getAbsolutePath()));
throw new RuntimeException(format(MESSAGES.getString("DIRECTORY_CREATION_FAILED"), output.getAbsolutePath()));
}
}
// output is a file
else {
// check if directory of outfile exist and create if required
if (!output.getParentFile().exists()) {
logger.debug(format(MESSAGES.getString("CREATING_DIRECTORY"), output.getParentFile().getAbsolutePath()));
if (!output.getParentFile().mkdirs()) {
// TODO: grace
throw new RuntimeException(format(MESSAGES.getString("DIRECTORY_CREATION_FAILED"), output.getParentFile().getAbsolutePath()));
}
}
}
}
Expand Down

0 comments on commit 6692356

Please sign in to comment.