From 5eb9b949a0383d7ab2162fd30949482b13f51e83 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 9 Aug 2022 09:02:27 +0200 Subject: [PATCH] Create directory first --- org.argeo.util/src/org/argeo/util/FsUtils.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/org.argeo.util/src/org/argeo/util/FsUtils.java b/org.argeo.util/src/org/argeo/util/FsUtils.java index 23839db74..cd61b5619 100644 --- a/org.argeo.util/src/org/argeo/util/FsUtils.java +++ b/org.argeo.util/src/org/argeo/util/FsUtils.java @@ -10,10 +10,7 @@ import java.nio.file.attribute.BasicFileAttributes; /** Utilities around the standard Java file abstractions. */ public class FsUtils { - /** - * Deletes this path, recursively if needed. Does nothing if the path does not - * exist. - */ + /** Deletes this path, recursively if needed. */ public static void copyDirectory(Path source, Path target) { if (!Files.exists(source) || !Files.isDirectory(source)) throw new IllegalArgumentException(source + " is not a directory"); @@ -22,13 +19,13 @@ public class FsUtils { try { Files.createDirectories(target); Files.walkFileTree(source, new SimpleFileVisitor() { + @Override - public FileVisitResult postVisitDirectory(Path directory, IOException e) throws IOException { - if (e != null) - throw e; + public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attrs) throws IOException { Path relativePath = source.relativize(directory); Path targetDirectory = target.resolve(relativePath); - Files.createDirectory(targetDirectory); + if (!Files.exists(targetDirectory)) + Files.createDirectory(targetDirectory); return FileVisitResult.CONTINUE; } -- 2.30.2