Skip to content

Commit

Permalink
Another update to FileUtils.safeCreate (now creates parent directories)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Mar 26, 2024
1 parent 5084ad3 commit 2ea63a9
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public static void safeCreate(Path target, OverwriteAction overwriteAction, IOWr
}

if (!(Boolean.TRUE.equals(fileExists) && OverwriteAction.SKIP.equals(overwriteAction))) {
Path parent = target.getParent();
if (parent != null) {
Files.createDirectories(parent);
}

boolean allowOverwrite = OverwriteAction.OVERWRITE.equals(overwriteAction);
// What to do if the tmp file already exists?
try (OutputStream out = Files.newOutputStream(tmpFile, allowOverwrite ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW)) {
Expand Down

0 comments on commit 2ea63a9

Please sign in to comment.