Skip to content

Commit 17e2fdb

Browse files
authored
[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
1 parent a70ddef commit 17e2fdb

File tree

1 file changed

+7
-33
lines changed
  • maven-resolver-util/src/main/java/org/eclipse/aether/util

1 file changed

+7
-33
lines changed

maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java

+7-33
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
import java.io.InputStream;
2424
import java.io.OutputStream;
2525
import java.nio.ByteBuffer;
26-
import java.nio.channels.FileChannel;
2726
import java.nio.file.Files;
2827
import java.nio.file.Path;
2928
import java.nio.file.StandardCopyOption;
30-
import java.nio.file.StandardOpenOption;
3129
import java.util.concurrent.ThreadLocalRandom;
3230
import java.util.concurrent.atomic.AtomicBoolean;
3331

@@ -39,7 +37,7 @@
3937
* @since 1.9.0
4038
*/
4139
public final class FileUtils {
42-
// Logic borrowed from Commons-Lang3: we really need only this, to decide do we fsync on directories or not
40+
// Logic borrowed from Commons-Lang3: we really need only this, to decide do we "atomic move" or not
4341
private static final boolean IS_WINDOWS =
4442
System.getProperty("os.name", "unknown").startsWith("Windows");
4543

@@ -66,6 +64,11 @@ public interface CollocatedTempFile extends TempFile {
6664
* Invocation of this method merely signals that caller ultimately wants temp file to replace the target
6765
* file, but when this method returns, the move operation did not yet happen, it will happen when this
6866
* instance is closed.
67+
* <p>
68+
* Invoking this method <em>without writing to temp file</em> {@link #getPath()} (thus, not creating a temp
69+
* file to be moved) is considered a bug, a mistake of the caller. Caller of this method should ensure
70+
* that this method is invoked ONLY when the temp file is created and moving it to its final place is
71+
* required.
6972
*/
7073
void move() throws IOException;
7174
}
@@ -125,13 +128,11 @@ public void move() {
125128

126129
@Override
127130
public void close() throws IOException {
128-
if (wantsMove.get() && Files.isReadable(tempFile)) {
131+
if (wantsMove.get()) {
129132
if (IS_WINDOWS) {
130133
copy(tempFile, file);
131134
} else {
132-
fsyncFile(tempFile);
133135
Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
134-
fsyncParent(tempFile);
135136
}
136137
}
137138
Files.deleteIfExists(tempFile);
@@ -157,33 +158,6 @@ private static void copy(Path source, Path target) throws IOException {
157158
}
158159
}
159160

160-
/**
161-
* Performs fsync: makes sure no OS "dirty buffers" exist for given file.
162-
*
163-
* @param target Path that must not be {@code null}, must exist as plain file.
164-
*/
165-
private static void fsyncFile(Path target) throws IOException {
166-
try (FileChannel file = FileChannel.open(target, StandardOpenOption.WRITE)) {
167-
file.force(true);
168-
}
169-
}
170-
171-
/**
172-
* Performs directory fsync: not usable on Windows, but some other OSes may also throw, hence thrown IO exception
173-
* is just ignored.
174-
*
175-
* @param target Path that must not be {@code null}, must exist as plain file, and must have parent.
176-
*/
177-
private static void fsyncParent(Path target) throws IOException {
178-
try (FileChannel parent = FileChannel.open(target.getParent(), StandardOpenOption.READ)) {
179-
try {
180-
parent.force(true);
181-
} catch (IOException e) {
182-
// ignore
183-
}
184-
}
185-
}
186-
187161
/**
188162
* A file writer, that accepts a {@link Path} to write some content to. Note: the file denoted by path may exist,
189163
* hence implementation have to ensure it is able to achieve its goal ("replace existing" option or equivalent

0 commit comments

Comments
 (0)