[ 
https://issues.apache.org/jira/browse/MNG-7820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17759577#comment-17759577
 ] 

ASF GitHub Bot commented on MNG-7820:
-------------------------------------

elharo commented on code in PR #1208:
URL: https://github.com/apache/maven/pull/1208#discussion_r1307372298


##########
maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java:
##########
@@ -465,6 +469,28 @@ public void getRemoteFile(
         }
     }
 
+    private void copyFile(File source, File destination) throws IOException {
+        String message;
+        if (!source.exists()) {
+            message = "File " + source + " does not exist";
+            throw new IOException(message);
+        } else if 
(!source.getCanonicalPath().equals(destination.getCanonicalPath())) {
+            File parentFile = destination.getParentFile();
+            if (parentFile != null && !parentFile.exists()) {
+                parentFile.mkdirs();

Review Comment:
   The existing code is buggy and can fail. There is no guarantee mkdirs 
succeeds here. 



##########
maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java:
##########
@@ -465,6 +469,28 @@ public void getRemoteFile(
         }
     }
 
+    private void copyFile(File source, File destination) throws IOException {
+        String message;
+        if (!source.exists()) {
+            message = "File " + source + " does not exist";
+            throw new IOException(message);
+        } else if 
(!source.getCanonicalPath().equals(destination.getCanonicalPath())) {
+            File parentFile = destination.getParentFile();
+            if (parentFile != null && !parentFile.exists()) {
+                parentFile.mkdirs();
+            }
+            Files.copy(
+                    source.toPath(),
+                    destination.toPath(),
+                    StandardCopyOption.REPLACE_EXISTING,
+                    StandardCopyOption.COPY_ATTRIBUTES);
+            if (source.length() != destination.length()) {

Review Comment:
   There's some shared history between all of these, and they have the same 
failure modes and issues. That's why we need to move away from all of them and 
use the JDK methods that are available in Java 7+ that did not exist 20 years 
ago when this buggy code was first written.





> Remove dependency on plexus-utils
> ---------------------------------
>
>                 Key: MNG-7820
>                 URL: https://issues.apache.org/jira/browse/MNG-7820
>             Project: Maven
>          Issue Type: Task
>            Reporter: Guillaume Nodet
>            Priority: Major
>             Fix For: 4.0.0-alpha-8
>
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to