You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/11/07 23:02:03 UTC

[GitHub] [maven-resolver] gnodet commented on a diff in pull request #216: [MRESOLVER-285] File locking tweaks for Windows OS

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


##########
maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/providers/FileLockNamedLockFactory.java:
##########
@@ -65,11 +95,45 @@ protected NamedLockSupport createLock( final String name )
             try
             {
                 Files.createDirectories( path.getParent() );
-                return FileChannel.open(
-                        path,
-                        StandardOpenOption.READ, StandardOpenOption.WRITE,
-                        StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE
-                );
+                FileChannel channel = retry( ATTEMPTS, SLEEP_MILLIS, () ->
+                {
+                    try
+                    {
+                        if ( DELETE_LOCK_FILES )
+                        {
+                            return FileChannel.open(
+                                    path,
+                                    StandardOpenOption.READ, StandardOpenOption.WRITE,
+                                    StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE
+                            );
+                        }
+                        else
+                        {
+                            return FileChannel.open(
+                                    path,
+                                    StandardOpenOption.READ, StandardOpenOption.WRITE,
+                                    StandardOpenOption.CREATE
+                            );
+                        }
+                    }
+                    catch ( AccessDeniedException e )
+                    {
+                        return null;
+                    }
+                }, null, null );
+
+                if ( channel == null )
+                {
+                    throw new IllegalStateException( "Could not open file channel for '"
+                            + name + "' after " + ATTEMPTS + " attempts; giving up" );
+                }
+                return channel;
+            }
+            catch ( InterruptedException e )
+            {
+                Thread.currentThread().interrupt();
+                throw new RuntimeException( "Interrupted during open file channel for '"

Review Comment:
   during -> while



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

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org