gnodet commented on issue #262:
URL: 
https://github.com/apache/maven-clean-plugin/issues/262#issuecomment-5803635630

   The root cause is clearly identified: `path.toRealPath()` on Windows fails 
for Docker volume mount reparse points because of JDK-8172711. This is called 
in `Cleaner.java` only when `followSymlinks=true`:
   
   ```java
   if (followSymlinks) {
       options.add(FileVisitOption.FOLLOW_LINKS);
       basedir = getCanonicalPath(basedir, null);  // <-- throws 
NoSuchFileException on Docker volumes
   }
   ```
   
   `getCanonicalPath` already has a recursive fallback that walks up to the 
parent and appends the filename, but on a Docker volume reparse point, even the 
parent resolution fails, so the exception propagates.
   
   **Proposed fix:**
   
   When `getCanonicalPath` ultimately fails (i.e., throws after exhausting all 
parent fallbacks), fall back to using the original unresolved path instead of 
propagating the exception. The `FOLLOW_LINKS` option has already been added to 
the `walkFileTree` options, so symlink following will still work — 
`toRealPath()` is only used here to canonicalize the start path for loop 
detection. Losing that canonicalization is benign in practice:
   
   ```java
   if (followSymlinks) {
       options.add(FileVisitOption.FOLLOW_LINKS);
       try {
           basedir = getCanonicalPath(basedir, null);
       } catch (IOException e) {
           logger.debug("Could not resolve real path of \"" + basedir + "\", 
using as-is: " + e);
           // Fall back to the original path; FOLLOW_LINKS is still active for 
the tree walk.
       }
   }
   ```
   
   This is the minimal, correct fix that restores pre-3.4.1 behavior for Docker 
Windows environments. It doesn't require any API or configuration change since 
`followSymlinks=false` is the default (so most users are never affected).
   
   Note: `toAbsolutePath()` (which is already used in `BackgroundCleaner` for a 
similar reason: "Note that we have to use `toAbsolutePath()` instead of 
`toRealPath()` because `fastDir` may not exist yet") would be another option, 
but for `followSymlinks=true` we specifically want symlink resolution, not just 
absolute path, so the try/catch fallback is more appropriate.
   
   Happy to open a PR with this fix.
   


-- 
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