diff options
author | Olivier Lamy <olamy@apache.org> | 2013-12-13 05:31:13 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-12-13 05:31:13 +0000 |
commit | a597458ba92ebbe4dedcecb167181d3b37b05b5d (patch) | |
tree | e0966d8feb810a9a9b735649ef7c569e10256cff /archiva-modules/archiva-base/archiva-filelock | |
parent | 76d1127f8bc5da3470d4f23a778b03b8b038964e (diff) | |
download | archiva-a597458ba92ebbe4dedcecb167181d3b37b05b5d.tar.gz archiva-a597458ba92ebbe4dedcecb167181d3b37b05b5d.zip |
track FileNotFoundException if a concurrent thread delete the file before locking and try recreate it
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1550647 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-filelock')
-rw-r--r-- | archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java b/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java index e25626f0a..feadc96f4 100644 --- a/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java +++ b/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java @@ -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 |