AlexanderBartash opened a new issue, #2317:
URL: https://github.com/apache/maven-resolver/issues/2317

   ### Affected version
   
   1.9.27 (latest 1.9.x, bundled in Maven 3.9.16). 2.0.23 and 2.0.25 keep the 
time, except in the classicCopy fallback.
   
   ### Bug description
   
   ## Summary
   
   > [!NOTE]
   > AI-generated.
   
   On Windows with Resolver 1.9.x, a file downloaded into the local repository 
gets the download time as its modification time.
   On Linux, and on Windows with Resolver 2.0.23+, it gets the time from the 
server's `Last-Modified` header, as intended by MRESOLVER-393 (#323).
   
   Tools that read the file time are affected. Example: `versions-maven-plugin` 
2.25 uses it as the publication date for its `minimumReleaseAge` filter, so on 
Windows with Maven 3.9.x every newly downloaded version is treated as 0 days 
old.
   
   ## Steps to reproduce
   
   Windows 11, Maven 3.9.16 (Resolver 1.9.27), Java 25.0.5. PowerShell:
   
   ```powershell
   mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.9.0:get 
"-Dartifact=org.jsoup:jsoup:1.24.1:pom" "-Dmaven.repo.local=D:\tmp\m2-test"
   
   (Get-Item 
D:\tmp\m2-test\org\jsoup\jsoup\1.24.1\jsoup-1.24.1.pom).LastWriteTimeUtc
   (Invoke-WebRequest -Method Head 
https://repo1.maven.org/maven2/org/jsoup/jsoup/1.24.1/jsoup-1.24.1.pom).Headers['Last-Modified']
   ```
   
   **Expected:** the file time equals the header, `Tue, 03 Nov 2026 03:40:51 
GMT`.
   
   **Actual:** the file time is the moment of the download, `2026-11-15 
16:21:25Z`.
   
   ## Tested combinations (2026-11-15, empty local repository each time)
   
   | OS | Maven (Resolver) | Transport | File time |
   |---|---|---|---|
   | Windows 11 | 3.9.16 (1.9.27) | default | download time |
   | Windows 11 | 3.10.1 (2.0.25) | default | `Last-Modified` |
   | Windows 11 | 4.0.0-rc-7 (2.0.23) | default | `Last-Modified` |
   | Ubuntu (WSL2) | 3.9.16 (1.9.27) | default | `Last-Modified` |
   
   ## AI Context
   
   <details>
   <summary>🤖 Fable 5.2 high: Technical context</summary>
   
   Cause, in `maven-resolver-1.9.27`:
   
   - `HttpTransporter.implGet` sets the time on the task's data file: 
`task.getDataFile().setLastModified(lastModified.getTime())`.
   - That data file is a temp file created by 
`BasicRepositoryConnector.GetTaskRunner.runTask` 
(`FileUtils.newTempFile(file.toPath())`, then `tempFile.move()`).
   - `FileUtils.newTempFile(Path)` → `CollocatedTempFile.close()`:
   
   ```java
   if (wantsMove.get()) {
       if (IS_WINDOWS) {
           copy(tempFile, file);
       } else {
           Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
       }
   }
   ```
   
   - `copy` is a stream copy (`Files.newInputStream` → 
`Files.newOutputStream`), so the target gets the current time and the time set 
by the transporter is lost.
   - File: 
`maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java`. The 
Windows branch comes from MRESOLVER-372 / MRESOLVER-441 and is unchanged at the 
head of `maven-resolver-1.9.x`.
   
   Reproducer without Maven or network, using `maven-resolver-util-1.9.27.jar`:
   
   ```java
   import java.nio.file.Files;
   import java.nio.file.Path;
   import java.nio.file.attribute.FileTime;
   import java.time.Instant;
   import org.eclipse.aether.util.FileUtils;
   
   public class Proof {
     public static void main(String[] args) throws Exception {
       Path target = Files.createTempDirectory("proof").resolve("target.pom");
       Instant published = Instant.parse("2026-11-03T03:40:51Z");
       try (FileUtils.CollocatedTempFile tempFile = 
FileUtils.newTempFile(target)) {
         Files.writeString(tempFile.getPath(), "<project/>");
         Files.setLastModifiedTime(tempFile.getPath(), 
FileTime.from(published));
         tempFile.move();
       }
       System.out.println("target mtime = " + 
Files.getLastModifiedTime(target).toInstant());
     }
   }
   ```
   
   ```
   > java -cp maven-resolver-util-1.9.27.jar Proof.java
   target mtime = 2026-11-15T16:20:43.859848800Z      (lost)
   > java "-Dos.name=Linux" -cp maven-resolver-util-1.9.27.jar Proof.java
   target mtime = 2026-11-03T03:40:51Z                (kept; same Windows 
machine, rename branch)
   ```
   
   Related:
   
   - 2.x: since #2083 (in 2.0.23), `PathProcessorSupport` renames on Windows 
(`retryingMove`), which keeps the time. Its `classicCopy` fallback still loses 
it: tested in isolation with 2.0.25, when the target is held open by another 
reader, the fallback warning is logged and the target gets the current time. 
This needs an existing, locked target, so it does not affect first downloads.
   - #2124 ported the Windows rename to 1.9.x and would have fixed this as a 
side effect. It was closed without merging and without comments.
   - Separate from this report: the wagon transport 
(`-Dmaven.resolver.transport=wagon`) does not set the file time on any OS. 
Tested on Linux with 1.9.27 and on Windows with 2.0.25.
   
   Possible fix for 1.9.x that keeps the copy: after `copy(tempFile, file)`, 
copy the time as well.
   
   ```java
   Files.setLastModifiedTime(file, Files.getLastModifiedTime(tempFile));
   ```
   
   The same line after `classicCopy(source, target)` in `retryingMove` would 
cover the 2.x fallback. Not prototyped.
   
   </details>
   


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