This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push: new 17e2fdb5 [MRESOLVER-441] Undo FileUtils changes for non-Windows (#377) 17e2fdb5 is described below commit 17e2fdb5c748be96e4d32306ba7342fc2b5e944d Author: Tamas Cservenak <ta...@cservenak.net> AuthorDate: Wed Nov 22 15:05:03 2023 +0100 [MRESOLVER-441] Undo FileUtils changes for non-Windows (#377) Undo changes to block that worked without any issue on non-Windows --- https://issues.apache.org/jira/browse/MRESOLVER-441 --- .../java/org/eclipse/aether/util/FileUtils.java | 40 ++++------------------ 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java index 0ec3880b..0a430f89 100644 --- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java +++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java @@ -23,11 +23,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.nio.file.StandardOpenOption; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicBoolean; @@ -39,7 +37,7 @@ import static java.util.Objects.requireNonNull; * @since 1.9.0 */ public final class FileUtils { - // Logic borrowed from Commons-Lang3: we really need only this, to decide do we fsync on directories or not + // Logic borrowed from Commons-Lang3: we really need only this, to decide do we "atomic move" or not private static final boolean IS_WINDOWS = System.getProperty("os.name", "unknown").startsWith("Windows"); @@ -66,6 +64,11 @@ public final class FileUtils { * Invocation of this method merely signals that caller ultimately wants temp file to replace the target * file, but when this method returns, the move operation did not yet happen, it will happen when this * instance is closed. + * <p> + * Invoking this method <em>without writing to temp file</em> {@link #getPath()} (thus, not creating a temp + * file to be moved) is considered a bug, a mistake of the caller. Caller of this method should ensure + * that this method is invoked ONLY when the temp file is created and moving it to its final place is + * required. */ void move() throws IOException; } @@ -125,13 +128,11 @@ public final class FileUtils { @Override public void close() throws IOException { - if (wantsMove.get() && Files.isReadable(tempFile)) { + if (wantsMove.get()) { if (IS_WINDOWS) { copy(tempFile, file); } else { - fsyncFile(tempFile); Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE); - fsyncParent(tempFile); } } Files.deleteIfExists(tempFile); @@ -157,33 +158,6 @@ public final class FileUtils { } } - /** - * Performs fsync: makes sure no OS "dirty buffers" exist for given file. - * - * @param target Path that must not be {@code null}, must exist as plain file. - */ - private static void fsyncFile(Path target) throws IOException { - try (FileChannel file = FileChannel.open(target, StandardOpenOption.WRITE)) { - file.force(true); - } - } - - /** - * Performs directory fsync: not usable on Windows, but some other OSes may also throw, hence thrown IO exception - * is just ignored. - * - * @param target Path that must not be {@code null}, must exist as plain file, and must have parent. - */ - private static void fsyncParent(Path target) throws IOException { - try (FileChannel parent = FileChannel.open(target.getParent(), StandardOpenOption.READ)) { - try { - parent.force(true); - } catch (IOException e) { - // ignore - } - } - } - /** * A file writer, that accepts a {@link Path} to write some content to. Note: the file denoted by path may exist, * hence implementation have to ensure it is able to achieve its goal ("replace existing" option or equivalent