You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/02/26 16:55:24 UTC

[maven-resolver] 01/01: Direct write

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch direct-write
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit 7b4c074fe53ce39f40abead43e12c070e721878b
Author: Michael Osipov <mi...@siemens.com>
AuthorDate: Sun Feb 26 17:36:48 2023 +0100

    Direct write
---
 .../org/eclipse/aether/internal/impl/DefaultFileProcessor.java   | 9 +++------
 .../eclipse/aether/internal/impl/DefaultTrackingFileManager.java | 9 ++++-----
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java
index 39028e99..44a76088 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java
@@ -35,7 +35,6 @@ import java.nio.file.StandardCopyOption;
 
 import org.eclipse.aether.spi.io.FileProcessor;
 import org.eclipse.aether.util.ChecksumUtils;
-import org.eclipse.aether.util.FileUtils;
 
 /**
  * A utility class helping with file-based operations.
@@ -77,11 +76,11 @@ public class DefaultFileProcessor implements FileProcessor {
     }
 
     public void write(File target, String data) throws IOException {
-        FileUtils.writeFile(target.toPath(), p -> Files.write(p, data.getBytes(StandardCharsets.UTF_8)));
+        Files.write(target.toPath(), data.getBytes(StandardCharsets.UTF_8));
     }
 
     public void write(File target, InputStream source) throws IOException {
-        FileUtils.writeFile(target.toPath(), p -> Files.copy(source, p, StandardCopyOption.REPLACE_EXISTING));
+        Files.copy(source, target.toPath(), StandardCopyOption.REPLACE_EXISTING);
     }
 
     public void copy(File source, File target) throws IOException {
@@ -90,10 +89,8 @@ public class DefaultFileProcessor implements FileProcessor {
 
     public long copy(File source, File target, ProgressListener listener) throws IOException {
         try (InputStream in = new BufferedInputStream(Files.newInputStream(source.toPath()));
-                FileUtils.CollocatedTempFile tempTarget = FileUtils.newTempFile(target.toPath());
-                OutputStream out = new BufferedOutputStream(Files.newOutputStream(tempTarget.getPath()))) {
+                OutputStream out = new BufferedOutputStream(Files.newOutputStream(target.toPath()))) {
             long result = copy(out, in, listener);
-            tempTarget.move();
             return result;
         }
     }
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java
index 793ece14..80ea1062 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java
@@ -31,7 +31,6 @@ import java.nio.file.Path;
 import java.util.Map;
 import java.util.Properties;
 
-import org.eclipse.aether.util.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,7 +45,7 @@ public final class DefaultTrackingFileManager implements TrackingFileManager {
     @Override
     public Properties read(File file) {
         Path filePath = file.toPath();
-        if (Files.isRegularFile(filePath)) {
+        if (Files.isReadable(filePath)) {
             try (InputStream stream = Files.newInputStream(filePath)) {
                 Properties props = new Properties();
                 props.load(stream);
@@ -86,15 +85,15 @@ public final class DefaultTrackingFileManager implements TrackingFileManager {
                 }
             }
 
-            FileUtils.writeFile(filePath, p -> {
-                try (OutputStream stream = Files.newOutputStream(p)) {
+            if (Files.isWritable(filePath)) {
+                try (OutputStream stream = Files.newOutputStream(filePath)) {
                     LOGGER.debug("Writing tracking file '{}'", file);
                     props.store(
                             stream,
                             "NOTE: This is a Maven Resolver internal implementation file"
                                     + ", its format can be changed without prior notice.");
                 }
-            });
+            }
         } catch (IOException e) {
             LOGGER.warn("Failed to write tracking file '{}'", file, e);
             throw new UncheckedIOException(e);