]> source.dussan.org Git - archiva.git/commitdiff
Additional improvement for file locks
authorMartin Stockhammer <martin_s@apache.org>
Thu, 27 Oct 2016 10:21:46 +0000 (12:21 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Thu, 27 Oct 2016 10:22:56 +0000 (12:22 +0200)
archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java
archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java

index 2ce2f188c2912f02d51cc0f5c159438c4fad90fd..258366aa94b65030e5492e446d39f4b1f88ace45 100644 (file)
@@ -198,28 +198,38 @@ public class DefaultFileLockManager
                 }
                 throw new FileLockException( e.getMessage(), e );
             }
-            catch ( Throwable e )
+            catch ( IllegalStateException e )
             {
+                // Ignore this
+                log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
+            } catch (Throwable t) {
                 if (lock!=null && lock.isValid()) {
                     try {
                         lock.close();
                     } catch (IOException ex) {
                         // Ignore
-                    } finally {
-                        lock = null;
                     }
                 }
-                log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
+                throw t;
             }
 
         }
 
         Lock current = lockFiles.putIfAbsent( file, lock );
+        if (lock!=null && lock != current) {
+            try {
+                lock.close();
+            } catch (IOException e) {
+                // ignore
+            }
+
+        }
         if ( current != null )
         {
             lock = current;
         }
 
+
         return lock;
 
 
index 96186612e9eb80264ced8c1e1d364e066cf9c7d3..19f836dbc16ca862161f9517d126db5a2c3c7248 100644 (file)
@@ -246,7 +246,7 @@ public class DefaultFileLockManagerTest
         public void thread9()
             throws FileLockException, FileLockTimeoutException, IOException
         {
-            logger.info( "thread7" );
+            logger.info( "thread9" );
             Lock lock = fileLockManager.writeFileLock( this.file );
             try
             {
@@ -274,7 +274,7 @@ public class DefaultFileLockManagerTest
             {
                 fileLockManager.release( lock );
             }
-            logger.info( "thread8 ok" );
+            logger.info( "thread10 ok" );
             success.incrementAndGet();
         }