desruisseaux commented on code in PR #2198:
URL: https://github.com/apache/maven-resolver/pull/2198#discussion_r4241741162


##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultInstaller.java:
##########
@@ -205,7 +214,22 @@ private void install(RepositorySystemSession session, 
RequestTrace trace, Artifa
                 throw new IllegalStateException("cannot install " + dstPath + 
" to same path");
             }
 
-            pathProcessor.copyWithTimestamp(srcPath, dstPath);
+            if (hardLink) {
+                Files.createDirectories(dstPath.getParent());
+                if (Files.isDirectory(dstPath)) {
+                    throw new IOException("destination is a directory: " + 
dstPath);
+                }
+                try {
+                    Files.deleteIfExists(dstPath);
+                    Files.createLink(dstPath, srcPath);
+                } catch (UnsupportedOperationException | 
IllegalArgumentException | IOException e) {
+                    // cross-device link (EXDEV), provider mismatch (e.g. 
Jimfs), or unsupported FS — fall back to copy
+                    logger.warn("Hard link not supported for {}, falling back 
to copy: {}", dstPath, e.getMessage());

Review Comment:
   Indeed, we may need a mechanism for avoiding duplication. But I would 
suggest a private `Exception linkFailures` field of something like that, and a 
some like below in the `catch` block:
   
   ```java
   if (linkFailures == null) {
       linkFailure = e;
   } else {
       linkFailures.addSuppressed(e);
   }
   ```
   
   and log `linkFailures` at the end, after all JAR have been installed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to