[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787174#comment-17787174
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas merged PR #365:
URL: https://github.com/apache/maven-resolver/pull/365




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787173#comment-17787173
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas merged PR #364:
URL: https://github.com/apache/maven-resolver/pull/364




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787126#comment-17787126
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1816117467

   So, to recap:
   * original issue is not related to locking at all
   * is about change done in 1.9 where file processor was altered to use nio2 
atomic move, inspiration was to prevent possibility of partial download being 
read by other process (and prevent incomplete files in case of crash).  Maven 
lrm uses layout, so randomized tmp files does not matter (if remain after 
crash) it would merely just clutter local repo.
   * nuking local repo is part of healthy hygiene
   * seems windows (or java on windows) have issues with atomic fs ops
   * resolver have no deps on p-u or any commons, api and util modules are zero 
dependency jars
   * one thing bugs me still: why does the old code work?




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787113#comment-17787113
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

michael-o commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1397013423


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -33,6 +39,10 @@
  * @since 1.9.0
  */
 public final class FileUtils {
+// Logic borrowed from Commons-Lang3: we really need only this, to decide 
do we fsync on directories or not
+private static final boolean IS_WINDOWS =
+System.getProperty("os.name", "unknown").startsWith("Windows");
+

Review Comment:
   > but if external library is not used I would not like add next dependency 
for one simple function
   
   With this, I agree, but if we use it anyway,  I wouldn't write the code 
myself.





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787087#comment-17787087
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

slawekjaranowski commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1396915657


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -33,6 +39,10 @@
  * @since 1.9.0
  */
 public final class FileUtils {
+// Logic borrowed from Commons-Lang3: we really need only this, to decide 
do we fsync on directories or not
+private static final boolean IS_WINDOWS =
+System.getProperty("os.name", "unknown").startsWith("Windows");
+

Review Comment:
   but if external library is not used I would not like add next dependency for 
one simple function





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787086#comment-17787086
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

slawekjaranowski commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1396909833


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -33,6 +39,10 @@
  * @since 1.9.0
  */
 public final class FileUtils {
+// Logic borrowed from Commons-Lang3: we really need only this, to decide 
do we fsync on directories or not
+private static final boolean IS_WINDOWS =
+System.getProperty("os.name", "unknown").startsWith("Windows");
+

Review Comment:
   and `SystemUtils` in commons-lang 





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-17 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787082#comment-17787082
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

michael-o commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1396865129


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -33,6 +39,10 @@
  * @since 1.9.0
  */
 public final class FileUtils {
+// Logic borrowed from Commons-Lang3: we really need only this, to decide 
do we fsync on directories or not
+private static final boolean IS_WINDOWS =
+System.getProperty("os.name", "unknown").startsWith("Windows");
+

Review Comment:
   I believe we have plexus utils code for this, no?



##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +111,79 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {
+if (IS_WINDOWS) {
+copy(tempFile, file);
+} else {
+fsyncFile(tempFile);
+Files.move(tempFile, file, 
StandardCopyOption.ATOMIC_MOVE);
+fsyncParent(tempFile);
+}
+}
 Files.deleteIfExists(tempFile);
 }
 };
 }
 
+/**
+ * On Windows we use pre-NIO2 way to copy files, as for some reason it 
works. Beat me why.

Review Comment:
   Beat, why?





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787043#comment-17787043
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

laeubi commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815804015

   > @laeubi me having done some analysis about file locking on windows. uhmmm 
LOL you may confuse with someone else ;)
   
   Hm... it should have been @michael-o sorry for the confusion no idea why 
github has suggested your name and I didn't notice :-D




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787039#comment-17787039
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

olamy commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815797221

   @laeubi me having done some analysis about file locking on windows. uhmmm 
LOL you may confuse with someone else ;) 




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17787033#comment-17787033
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

laeubi commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815784844

   @cstamas I'm a bit late to the party **but** as @rdicroce already tested 
showed I cna only tell that Maven 3.8.x ("old"? resolver) has worked under 
Windows why upgrade to 3.9.x ("new"? resolver) shows reproducible problems in 
this regard.
   
   I'm not a windows expert enough to tell but think @olamy  has done already 
some analysis in the past about the Move/Sync problem.
   
   In general I think it would really be beneficial if resolver would simply 
use time-stamped SNAPSHOTs instead of "normalized", maybe one can even for a 
while simply **write** the SNAPSHOT as an additional file (on windows) and  
**symlink** under Linux but resolver use/returns the timestamped file to start 
a migration?




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786938#comment-17786938
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815289902

   I propose this last change as final PR, will ask for re-review from everyone 
adding review so far.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786936#comment-17786936
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

rdicroce commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815268637

   @cstamas #365 works on my machine.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786932#comment-17786932
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815231993

   @rdicroce updated this but also the backport PR 
https://github.com/apache/maven-resolver/pull/365
   
   Please try!




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786925#comment-17786925
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815208135

   Wow, @rdicroce Thanks for testing this!
   
   So, this for me proves even more, that problem lies within WindowsFS
   
   As I said, my intent with use of "atomic moves" was actually to prevent 
other processes to end up reading partially written file content... And this 
code @rdicroce tested, while does, does not prevent this 
   
   So, maybe IF win old_code ELSE new_code? Hm




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786923#comment-17786923
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

rdicroce commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815195848

   So for shits and giggles, I decided to paste the 1.6.0 file copy code into 
the 1.9.x branch. Here's what it looks like:
   
   ```
   public static CollocatedTempFile newTempFile(Path file) throws 
IOException {
   Path parent = requireNonNull(file.getParent(), "file must have 
parent");
   Files.createDirectories(parent);
   Path tempFile = parent.resolve(file.getFileName() + "."
   + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
   return new CollocatedTempFile() {
   @Override
   public Path getPath() {
   return tempFile;
   }
   
   @Override
   public void move() throws IOException {
try (InputStream in = Files.newInputStream(tempFile); 
OutputStream out = Files.newOutputStream(file)) {
copy(out, in);
}
   }
   
   @Override
   public void close() throws IOException {
   Files.deleteIfExists(tempFile);
   }
   };
   }
   
   private static long copy( OutputStream os, InputStream is )
   throws IOException
   {
   long total = 0L;
   
   ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 );
   byte[] array = buffer.array();
   
   while ( true )
   {
   int bytes = is.read( array );
   if ( bytes < 0 )
   {
   break;
   }
   
   os.write( array, 0, bytes );
   
   total += bytes;
   }
   
   return total;
   }
   ```
   
   Then I tried the same test as before. This code did NOT throw an exception. 
And it appears to have actually worked. The file on disk has different 
timestamps inside the JAR. Eclipse even seems to have noticed that it changed, 
although that's difficult to say for sure.
   
   Why does this work and the other code doesn't? I have no idea. Probably has 
something to do with the fact that this code actually copies the content of the 
file, byte by byte. Whereas the MoveFile approach probably only tries to change 
the actual location on disk that the file points to.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786895#comment-17786895
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

So far as I see, the statement "Download fails if file is currently in use 
under windows" was true for any resolver (when on windows), even the pre-1.9 
resolver did fail, it did not "forgive" or swallow IOExceptions. So this issue 
not that is unrelated to locking, but is "red herring" in general, as this was 
happening before resolver 1.9, with resolver 1.9, and will happen after it as 
well. Simply put, let Maven manage local repository ONLY, or, ask your OS 
vendor to do something about this.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786893#comment-17786893
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1815036588

   Similarly, @laeubi i don't see pre1.9 resolver code as "forgiving" and 
swallowing IOEx, here is the same method from 1.6.0:
   
https://github.com/apache/maven-resolver/blob/maven-resolver-1.6.0/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java#L153
   
   If target is open, line 166 would fail, no?
   
   So to me it seems "when file is opened by something else" failed Resolver 
1.6.0 as well. So, imho, this use case is red herring: we cannot do anything 
here.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786882#comment-17786882
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814992318

   There is one use case I have no idea what to do with, but I do know what I 
don't want to do:
   
   > If a file is open for any reason, it can't be replaced. (on Windows)
   
   In this case, if resolver would "silently give up" (for example an 
installation attempt), it would mean it is _**intentionally** leaving your 
local repository in an **inconsistent state**_. And this is unacceptable for 
me. Hence, "ignoring IOExceptions" i consider as a non-option: no software 
should intentionally make transition from "consistent" to "inconsistent" state.
   
   Least I can do is implemented similar trick as for directory fsync, and make 
resolver broken on windows. But this would imply, that we have to state 
somewhere (release notes? site?) that "by design, resolver is not supported on 
Windows"?




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786862#comment-17786862
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

gnodet commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1396050259


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {

Review Comment:
   Ok, so order is specified as being the reversed order of declaration, which 
makes sense of course, so this should work because the BufferedOutputStream 
will be closed just before the CollocatedTempFile.





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786859#comment-17786859
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

gnodet commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1396043178


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {

Review Comment:
   This is not safe.  The `CollocatedTempFile` should provide a way to create 
an `OutputStream` so that it can be closed before the `CollocatedTempFile`.   
This is needed so that buffered streams are fully written to disk before moving 
the file.
   See 
https://github.com/apache/maven-resolver/blob/e721b01be9576396e36e4167da337180b44e38e9/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java#L90-L96
   The code is using a `BufferedOutputStream` so that it may not be completely 
written to the disk.  I'm not sure if there's any guarantee on the ordering of 
the `close()` methods in the `try/finally` block.





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786854#comment-17786854
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

gnodet commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1396036846


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {
+fsyncFile(tempFile);
+Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+if (!IS_WINDOWS) {
+fsyncParent(tempFile);
+}

Review Comment:
   If the `fsync` is not important, then this commit is nearly wrong.  If 
should simply be a matter of making sure the calls are ordered correctly ?
   
https://github.com/apache/maven-resolver/blob/c6b8a728727220a4362b45e50317deb40562c0bc/maven-resolver-connector-basic/src/main/java/org/eclipse/aether/connector/basic/BasicRepositoryConnector.java#L496
   The call to move should be performed after the commit which actually writes 
to the file ?





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786841#comment-17786841
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

rdicroce commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814805054

   I tested this on Windows and it does not fix the problem. The way I tested 
it was:
   
   1. Build the #365 branch.
   2. Replace all of the maven-resolver JARs in Eclipse's 
plugins\org.eclipse.m2e.maven.runtime_3.9.400.20230826-0755\jars directory by 
renaming the originals to have .orig on the end, and then changing the names of 
the built JARs to match the 1.9.14 filenames. I'm using Eclipse 2023-09.
   3. Open a workspace containing project A. This project has a SNAPSHOT 
dependency on project B.
   4. Open a second workspace containing project B.
   5. Run a 'clean install' build of project B.
   
   I agree with @laeubi's assessment. If a file is open for any reason, it 
can't be replaced. At least, I've never heard of any way of doing it on 
Windows. Linux is a different story.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786778#comment-17786778
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

I'd be very grateful for some feedback of those who use Windows...

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786776#comment-17786776
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1395807029


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {
+fsyncFile(tempFile);
+Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+if (!IS_WINDOWS) {
+fsyncParent(tempFile);
+}
+}
 Files.deleteIfExists(tempFile);
 }
 };
 }
 
+/**
+ * Performs fsync: makes sure no OS "dirty buffers" exist for given file.
+ *
+ * @param target Path that must not be {@code null}, must exist as plain 
file.
+ */
+private static void fsyncFile(Path target) throws IOException {
+try (FileChannel file = FileChannel.open(target, 
StandardOpenOption.WRITE)) {
+file.force(true);
+}

Review Comment:
   Lucene code in case of file does not ignore exception, so I think we should 
not either.



##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {
+fsyncFile(tempFile);
+Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+if (!IS_WINDOWS) {
+fsyncParent(tempFile);
+}

Review Comment:
   https://github.com/apache/maven-resolver/pull/364#issuecomment-1814516829





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> 

[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786774#comment-17786774
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

slawekjaranowski commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1395786775


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {
+fsyncFile(tempFile);
+Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+if (!IS_WINDOWS) {
+fsyncParent(tempFile);
+}
+}
 Files.deleteIfExists(tempFile);
 }
 };
 }
 
+/**
+ * Performs fsync: makes sure no OS "dirty buffers" exist for given file.
+ *
+ * @param target Path that must not be {@code null}, must exist as plain 
file.
+ */
+private static void fsyncFile(Path target) throws IOException {
+try (FileChannel file = FileChannel.open(target, 
StandardOpenOption.WRITE)) {
+file.force(true);
+}

Review Comment:
   should we also ignore exception here as is in `fsyncParent`?





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786773#comment-17786773
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

slawekjaranowski commented on code in PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#discussion_r1395782170


##
maven-resolver-util/src/main/java/org/eclipse/aether/util/FileUtils.java:
##
@@ -98,23 +108,59 @@ public static CollocatedTempFile newTempFile(Path file) 
throws IOException {
 Path tempFile = parent.resolve(file.getFileName() + "."
 + 
Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
 return new CollocatedTempFile() {
+private final AtomicBoolean wantsMove = new AtomicBoolean(false);
+
 @Override
 public Path getPath() {
 return tempFile;
 }
 
 @Override
-public void move() throws IOException {
-Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+public void move() {
+wantsMove.set(true);
 }
 
 @Override
 public void close() throws IOException {
+if (wantsMove.get() && Files.isReadable(tempFile)) {
+fsyncFile(tempFile);
+Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
+if (!IS_WINDOWS) {
+fsyncParent(tempFile);
+}

Review Comment:
   Why here ... delete tempFile can also change directory content ... so maybe 
should be sync after delete





> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786766#comment-17786766
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814516829

   Frankly, I'd remove the fsync on directory, as unlike Lucene (that depends 
on readability of new commit marker), Maven uses layout, so any other process 
will calculate the path and go directly for artifact jar




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786741#comment-17786741
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814394810

   @slawekjaranowski @laeubi reworked fully...
   
   After a LOT of reading, seemingly we had several issues:
   * move() call literally MOVED the file, but the writer of that file may kept 
the file still opened for write
   * due that above and also due lack of fsync() Windows MAY detect "dirty 
buffers", hence AccessDeniedEx
   * on non-Windows is recommended to fsync() the containing directory as well




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786713#comment-17786713
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

laeubi commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814261616

   > I really hope "atomic on windows" will NOT replace the file and then throw 
 otherwise, am really unsure what that OS is able to guarantee for at all.
   
   You can just look into the Widnows File system implementation of the JDK to 
see whats going on.
   
   > If you check older resolvers (and let's assume "they worked"), they used 
pre-nio2 copy+delete
   
   "Old" code simply ignored when replace goes wrong, so you have the problem 
that afterwards you maybe use the old file. I don't say that new way is "wrong" 
just that not using atomic move does not solve the problem reported in the 
issue that is some other process (or the current) is currently opend that file 
and in such case you cam't overwrite/delete/replace/move ... to that file under 
windows.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Assignee: Tamas Cservenak
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786702#comment-17786702
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

So, just to recap:
* this has nothing to do with locking (we do not lock artifact or metadata 
files)
* Pre 1.9 resolver did the very same thing, no change in this area (it also 
normalized snapshots and replaced files on download/install).
* The ONLY change in this respect Resolver 1.9 did is change the move operation 
implementation from pre-nio2 (as it was in 1.8) to nio2 + atomic (1.9).

So, my guts are telling me that the culprit is "atomic" on Windows. The reason 
for atomic is to prevent partially written files being read by some other 
process (ie IDE).

Also, according to that above, Resolver 1.8 was also normalizing snapshots and 
was rewriting files (if existing) on install/resolve, hence very same problems 
would be reported against it as well, but are not. 

Hence, I am pretty sure it is "atomic" that is the culrpit of this issue... 
Please test the PR.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786696#comment-17786696
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814162045

   If you check older resolvers (and let's assume "they worked"), they used 
pre-nio2 copy+delete, so they also did this but with a "window of possibility" 
to allow other process to read partially written file. That was implemented 
using pre-nio2 Java. All that resolver 1.9.x did, is to migrate the code to 
nio2 AND use atomic. My guts are telling me that the "atomic" is the problem 
here...




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-16 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786695#comment-17786695
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas commented on PR #364:
URL: https://github.com/apache/maven-resolver/pull/364#issuecomment-1814159292

   I really hope "atomic on windows" will NOT replace the file and then throw 
:smile: otherwise, am really unsure what that OS is able to guarantee for at 
all.




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786543#comment-17786543
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas opened a new pull request, #365:
URL: https://github.com/apache/maven-resolver/pull/365

   This seems to affect Windows only
   
   ---
   
   https://issues.apache.org/jira/browse/MRESOLVER-372




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786544#comment-17786544
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

For Maven 3.9 all you need is to build this 
https://github.com/apache/maven-resolver/pull/365
(and replace resolver in maven)

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786539#comment-17786539
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

For start created https://github.com/apache/maven-resolver/pull/364

Would be grateful if Windows users would test this.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786538#comment-17786538
 ] 

ASF GitHub Bot commented on MRESOLVER-372:
--

cstamas opened a new pull request, #364:
URL: https://github.com/apache/maven-resolver/pull/364

   This seems to affect Windows only
   
   ---
   
   https://issues.apache.org/jira/browse/MRESOLVER-372




> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786524#comment-17786524
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

What I found so far:
https://stackoverflow.com/questions/167414/is-an-atomic-file-rename-with-overwrite-possible-on-windows
https://stackoverflow.com/questions/25238284/how-to-guarantee-atomic-move-or-exception-of-a-file-in-java

And same here: if Windows would throw "atomic not supported" that would be 
perfectly fine, but the problem is that it does not. In fact, it "works" and 
sometimes it throws AccessDeniedEx, seemingly at random cases.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786522#comment-17786522
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

Just to shed some light what code does:
* you have some new content (ie. downloaded or built, so resolve or install 
case)
* the target file may or may not exists
* the code writes to tmp/random file _in same directory_ (so it is not cross FS 
or whatever atomic move even, it is happening within same god damn directory)
* once the file is written to tmp file, atomic rename to "final file" is done

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786518#comment-17786518
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

>From this aspect (again, this is locking unrelated, resolver does NOT lock 
>artifacts!), given that resolver 1.8 pre-nio2 code "worked" and now nio2 
>atomic move "does not work" (while it does work on all the other OS-es), am 
>inclined to introduce alt-path IF OS is windows, and fallback to what resolver 
>1.8 did there, but use atomic move on modern OS-es.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-15 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17786515#comment-17786515
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

The more I read about the issue "atomic file move on windows" (and related) am 
more and more inclined to say that "atomic move" on Windows is like Russian 
roulette: sometimes it works, sometimes not.

The strange thing to me is this: in local repository, release artifacts are 
immutable, snapshots are also (sans the "snapshot normalization" also reported, 
but that can be tuned in resolver, see config), and the per-definitionem 
mutable files are metadata files, but NOBODY reported this issue for metadata 
files! (one possible reason: they are not kept open by IDEs, but are "one time 
read" and processed, most probably).

Other thing: this is NOT in whatsoever relation to "locking" introduced in 
1.9.x, actually to me this seems totally unrelated to it. Resolver does NOT 
lock artifact files (!), it does use "parallel hierarchy" to implement "mutual 
exclusive advisory locking" (so other mvn 3.9 will go for those "parallel" 
paths and mutually exclude).

This is all about "atomic move" Java support on Windows, as related code have 
only one change: old resolver (1.8 and before) did the good old "copy+delete 
src" using pre-nio2, while resolver 1.9 insist on "Files.move(atomic)" but the 
only reason for that is to prevent other processes to read partially written 
files

Am still looking, but anyone having any idea, shoot!

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-10 Thread Slawomir Jaranowski (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17785037#comment-17785037
 ] 

Slawomir Jaranowski commented on MRESOLVER-372:
---

Next case - I think connected: https://github.com/apache/maven-mvnd/issues/862

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>  Components: Resolver
>Reporter: Christoph Läubrich
>Priority: Major
> Fix For: 2.0.0, 1.9.17
>
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-09 Thread Jira


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17784330#comment-17784330
 ] 

Christoph Läubrich commented on MRESOLVER-372:
--

[~sjaranowski] as I really like to see this fixed ( [~cstamas] *please help 
here* ) as this makes maven 3.9 unusable in so many cases under windows, for a 
maven plugin there is a small little chance to mitigate this by using

{code}
try (SyncContext syncContext = 
syncContextFactory.newInstance(repositorySession, false)) {
Set lockList = new HashSet<>();
... add all interesting artifacts here ...
syncContext.acquire(lockList, null);
... do something with it ...
}
{code}

of course this is not suitable for any other third party app (e.g. IDE) outside 
maven that might accessing files from the local repo.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-09 Thread Slawomir Jaranowski (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17784327#comment-17784327
 ] 

Slawomir Jaranowski commented on MRESOLVER-372:
---

https://github.com/mojohaus/exec-maven-plugin/pull/392

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-11-07 Thread Slawomir Jaranowski (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17783779#comment-17783779
 ] 

Slawomir Jaranowski commented on MRESOLVER-372:
---

Also occurs when multiple process use the same local repository.
Eg in exec-maven-plugin ITs are executed in parallel, and error is:

{noformat}
Caused by: java.nio.file.AccessDeniedException: 
D:\a\exec-maven-plugin\exec-maven-plugin\target\local-repo\org\apache\maven\shared\maven-shared-utils\0.1\maven-shared-utils-0.1.pom.15783817563503912351.tmp
 -> 
D:\a\exec-maven-plugin\exec-maven-plugin\target\local-repo\org\apache\maven\shared\maven-shared-utils\0.1\maven-shared-utils-0.1.pom
at sun.nio.fs.WindowsException.translateToIOException 
(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException 
(WindowsException.java:97)
at sun.nio.fs.WindowsFileCopy.move (WindowsFileCopy.java:301)
at sun.nio.fs.WindowsFileSystemProvider.move 
(WindowsFileSystemProvider.java:287)
at java.nio.file.Files.move (Files.java:1395)
at org.eclipse.aether.util.FileUtils$2.move (FileUtils.java:108)
at 
org.eclipse.aether.connector.basic.BasicRepositoryConnector$GetTaskRunner.runTask
 (BasicRepositoryConnector.java:500)
at 
org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run 
(BasicRepositoryConnector.java:414)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.get 
(BasicRepositoryConnector.java:260)
{noformat}

do we have re-try option here?

https://github.com/mojohaus/exec-maven-plugin/actions/runs/6603309437/job/18457179181?pr=384


> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-10-11 Thread Rich DiCroce (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17774037#comment-17774037
 ] 

Rich DiCroce commented on MRESOLVER-372:


Tamas, you read my mind. :)

Making the cache CAS-like could be handy. Early drafts of the SLSA spec 
required content-addressable caches for levels 3 and 4, but it looks like the 
final draft removed that. Probably because it was infeasible due to the 
popularity of build systems like Maven that don't currently comply with it. But 
as you said, making a change that large could be a problem for other code that 
assumes Maven caches are laid out in a particular way. That's why I suggested 
to just use timestamped files, since that's a smaller change that's less likely 
to break things.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-10-11 Thread Jira


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17773917#comment-17773917
 ] 

Christoph Läubrich commented on MRESOLVER-372:
--

I think one should not deny such feature because there might be others that 
using it currently wrong. Using timestamped snapshots seems good solution here.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-10-10 Thread Tamas Cservenak (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17773821#comment-17773821
 ] 

Tamas Cservenak commented on MRESOLVER-372:
---

This is very cool! Thank you for your investigation, time and "thought 
experiments", i really like them. 

Yes, snapshot normalization (the thing that copies the latest downloaded 
TIMESTAMPED snapshot to -SNAPSHOT in local repository) is probably the culprit, 
and IF maven local repository could have immutable files (like releases are), 
it would be the simplest. Ideally, am keen to wild experiments even to make 
local repo CAS-like (content addressable storage), but to achieve that, we must 
"herd" all the code (authors) to strictly adhere and use Resolver APIs to 
figure out where the artifact belonging file is, and we still struggle with 
ancient codebases running in Maven...

I think "maven resolver dealing with which timestamped snapshot to use" is 
doable even without depending on local clock, but I see a bigger problem "all 
the rest of the world", that as I said, have copy-pasted code and assume local 
repo layout and so on... 

A big :thumbsup: for this comment.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-10-10 Thread Michael Osipov (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17773812#comment-17773812
 ] 

Michael Osipov commented on MRESOLVER-372:
--

As far as I remember, Maven Install Plugin delegates the installation to 
Resolver as well..

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-10-10 Thread Rich DiCroce (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17773776#comment-17773776
 ] 

Rich DiCroce commented on MRESOLVER-372:


I've been investigating why the most recent versions of Eclipse throw errors 
when trying to update snapshots, and ended up here. IMO this problem can only 
be properly fixed by changes to Maven Resolver, but the situation is 
complicated. It's important to note that the rest of what I write is about the 
exception posted in the original description of this issue. The exception 
posted by Delany in the comment above is NOT the same issue.

The top-level problem is that Eclipse has an open handle to the JAR file. On 
Windows, this prevents the file from being replaced. So we start going down the 
rabbit hole. Why does Eclipse have an open handle to the JAR file? I found that 
there are at least three separate answers:
 # m2e loads Maven plugins so they can be executed during builds
 # Eclipse JDT loads the project's dependencies if annotation processing is 
enabled
 # PMD Eclipse Plugin also loads the project's dependencies if "Enable using 
Java Project Build Path" is enabled

But all three of these boil down to the same problem: they need to construct a 
URLClassLoader so they can load classes from the JARs. The classloader is the 
thing that is actually holding the open handle.

Okay, so the problem could be solved by not holding on to the classloader. 
Except that's probably not feasible. An IDE needs to support incremental 
compilation. That means state needs to be retained between builds, which could 
mean that the classloader can't just be discarded.

Well then, maybe the classloader itself could be changed to not hold open 
references to the JARs? That seems like it could cause all sorts of havoc if a 
JAR was replaced, and some classes are loaded from the old JAR and some classes 
get loaded from the new JAR. I doubt the JDK maintainers would be willing to 
accept a change like that.

Okay, so we have to hold on to the classloader and the classloader has to hold 
on to the JARs. What if we just copied the JARs to some temp directory? Well, 
we could do that... but then every single part of the IDE that needs to load 
the project's plugins or dependencies has to implement that. That could be a 
lot of changes in a lot of places. And if any part of the IDE doesn't do that, 
the problem comes back and is very painful to locate.

Which brings us to the conclusion I arrived at: the right solution is to just 
not replace the JARs at all. So I started digging through the Maven Resolver 
code and found the aether.artifactResolver.snapshotNormalization option. When 
this option is enabled (which is the default), Maven Resolver first downloads a 
new snapshot to a timestamped JAR file, then copies that JAR to the -SNAPSHOT 
file.

Okay, so we just need to disable that option and our problem is solved! Except 
it's not. For one thing, locally built JARs are always written to the -SNAPSHOT 
file. So if you have two Eclipse workspaces open, and you're building a JAR in 
one workspace that is needed by the other workspace, you're still going to have 
the same problem. Secondly, from reading the code, it looks like Maven Resolver 
always looks for the -SNAPSHOT file first, precisely because that's where a 
locally built JAR is always installed. So if we turn off normalization and we 
already have a -SNAPSHOT file, then we'll never actually use any new snapshots 
we download from a server.

That brings us to my proposed solution: the -SNAPSHOT file must die. Instead, 
all snapshot JARs must have timestamped filenames so that the JAR files are 
always immutable. Achieving this requires some big changes though:
 * maven-install-plugin would need an option to install timestamped snapshots. 
For backwards compatibility, this would have to be off by default.
 * Maven Resolver would need to deal with timestamped, locally-built snapshots. 
It would also have to deal with -SNAPSHOT files written by older versions, 
which probably means changing the way it decides which snapshot to use. Perhaps 
it could look at all the eligible snapshots and use the one with the newest 
file modification time. (Of course, then you're depending on the system clock 
to be sane, which isn't great either.)

I'm not an expert on any of the internals here, so there may be other headaches 
I haven't thought of. Even if we can get consensus on how to fix this, I don't 
have time to work on it right now. I've already spent more time investigating 
this than I should have. But I figured it was worth it to document my findings 
so someone else can take a crack at it.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
>

[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-07-12 Thread Delany (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17742314#comment-17742314
 ] 

Delany commented on MRESOLVER-372:
--

Can happen at the end of a large deployAtEnd build
{code:java}
09:46:47  [INFO] Retrying deployment attempt 3 of 3
...
09:50:10  Caused by: java.nio.file.AccessDeniedException: 
maven-metadata--snapshots.xml.12223878285861141839.tmp -> 
maven-metadata--snapshots.xml
09:50:10      at sun.nio.fs.WindowsException.translateToIOException 
(WindowsException.java:89)
09:50:10      at sun.nio.fs.WindowsException.rethrowAsIOException 
(WindowsException.java:103)
09:50:10      at sun.nio.fs.WindowsFileCopy.move (WindowsFileCopy.java:309)
09:50:10      at sun.nio.fs.WindowsFileSystemProvider.move 
(WindowsFileSystemProvider.java:292)
09:50:10      at java.nio.file.Files.move (Files.java:1422)
09:50:10      at org.eclipse.aether.util.FileUtils$2.move (FileUtils.java:108)
09:50:10      at 
org.eclipse.aether.connector.basic.BasicRepositoryConnector$GetTaskRunner.runTask
 (BasicRepositoryConnector.java:500)
09:50:10      at 
org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run 
(BasicRepositoryConnector.java:414)
09:50:10      at 
org.eclipse.aether.connector.basic.BasicRepositoryConnector.get 
(BasicRepositoryConnector.java:215)
09:50:10      at org.eclipse.aether.internal.impl.DefaultDeployer.upload 
(DefaultDeployer.java:367)
09:50:10      at org.eclipse.aether.internal.impl.DefaultDeployer.deploy 
(DefaultDeployer.java:238)
09:50:10      at org.eclipse.aether.internal.impl.DefaultDeployer.deploy 
(DefaultDeployer.java:201)
09:50:10      at 
org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy 
(DefaultRepositorySystem.java:392)
09:50:10      at org.apache.maven.plugins.deploy.AbstractDeployMojo.deploy 
(AbstractDeployMojo.java:139)
09:50:10      at org.apache.maven.plugins.deploy.DeployMojo.deployAllAtOnce 
(DeployMojo.java:251)
09:50:10      at org.apache.maven.plugins.deploy.DeployMojo.execute 
(DeployMojo.java:218) {code}
Maven 3.9.3

-Daether.syncContext.named.factory=file-lock
-Daether.syncContext.named.nameMapper=file-gav

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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


[jira] [Commented] (MRESOLVER-372) Download fails if file is currently in use under windows

2023-06-19 Thread Michael Osipov (Jira)


[ 
https://issues.apache.org/jira/browse/MRESOLVER-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17734354#comment-17734354
 ] 

Michael Osipov commented on MRESOLVER-372:
--

See also MRESOLVER-325 for explanation.

> Download fails if file is currently in use under windows
> 
>
> Key: MRESOLVER-372
> URL: https://issues.apache.org/jira/browse/MRESOLVER-372
> Project: Maven Resolver
>  Issue Type: Bug
>Reporter: Christoph Läubrich
>Priority: Major
>
> With the new file-locking in maven-resolver there is a problem under windows 
> if the file is currently used by another process (this can for example happen 
> in an IDE ...) and resolver likes to move the file:
>  
> {code:java}
>  Caused by: java.nio.file.AccessDeniedException: 
> xxx-SNAPSHOT.jar.15463549870494779429.tmp -> -SNAPSHOT.jar
>         at 
> java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>         at 
> java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>         at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:317)
>         at 
> java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:293)
>         at java.base/java.nio.file.Files.move(Files.java:1432)
>         at org.eclipse.aether.util.FileUtils$2.move(FileUtils.java:108)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:96)
>         at 
> org.eclipse.aether.internal.impl.DefaultFileProcessor.copy(DefaultFileProcessor.java:88)
>         at 
> org.eclipse.aether.internal.impl.DefaultArtifactResolver.getFile(DefaultArtifactResolver.java:490)
>         ... 30 more{code}
>  
> My suggestion would be that resolver simply uses the temp file if it can't be 
> moved to final location and marks it as delete on exit. Even though this is 
> not optimal, it at least ensures the the build does not fail to the cost that 
> next time the file needs to be downloaded again.



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