]> source.dussan.org Git - archiva.git/commitdiff
track FileNotFoundException if a concurrent thread delete the file before locking...
authorOlivier Lamy <olamy@apache.org>
Fri, 13 Dec 2013 05:31:13 +0000 (05:31 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 13 Dec 2013 05:31:13 +0000 (05:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1550647 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java

index e25626f0a66dda81050c597b1ab6e60fa74d4a2f..feadc96f4d05ecf7a2490d288a4e54f99d137571 100644 (file)
@@ -94,10 +94,15 @@ public class DefaultFileLockManager
 
                 try
                 {
-                    file.createNewFile();
                     lock.openLock( false, timeout > 0 );
                     acquired = true;
                 }
+                catch ( FileNotFoundException e )
+                {
+                    // can happen if an other thread has deleted the file
+                    log.debug( "read Lock skip: {} try to create file", e.getMessage() );
+                    createNewFileQuietly( file );
+                }
                 catch ( IOException e )
                 {
                     throw new FileLockException( e.getMessage(), e );
@@ -169,6 +174,12 @@ public class DefaultFileLockManager
                     lock.openLock( true, timeout > 0 );
                     acquired = true;
                 }
+                catch ( FileNotFoundException e )
+                {
+                    // can happen if an other thread has deleted the file
+                    log.debug( "write Lock skip: {} try to create file", e.getMessage() );
+                    createNewFileQuietly( file );
+                }
                 catch ( IOException e )
                 {
                     throw new FileLockException( e.getMessage(), e );
@@ -187,13 +198,31 @@ public class DefaultFileLockManager
 
             return lock;
         }
-        catch ( FileNotFoundException e )
+
+        catch (
+
+            FileNotFoundException e
+
+            )
+
         {
             throw new FileLockException( e.getMessage(), e );
         }
 
     }
 
+    private void createNewFileQuietly( File file )
+    {
+        try
+        {
+            file.createNewFile();
+        }
+        catch ( IOException e )
+        {
+            // skip that
+        }
+    }
+
     @Override
     public void release( Lock lock )
         throws FileLockException