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
This commit is contained in:
Olivier Lamy 2013-12-13 05:31:13 +00:00
parent 76d1127f8b
commit a597458ba9
1 changed files with 31 additions and 2 deletions

View File

@ -94,10 +94,15 @@ public class DefaultFileLockManager
try try
{ {
file.createNewFile();
lock.openLock( false, timeout > 0 ); lock.openLock( false, timeout > 0 );
acquired = true; 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 ) catch ( IOException e )
{ {
throw new FileLockException( e.getMessage(), e ); throw new FileLockException( e.getMessage(), e );
@ -169,6 +174,12 @@ public class DefaultFileLockManager
lock.openLock( true, timeout > 0 ); lock.openLock( true, timeout > 0 );
acquired = true; 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 ) catch ( IOException e )
{ {
throw new FileLockException( e.getMessage(), e ); throw new FileLockException( e.getMessage(), e );
@ -187,13 +198,31 @@ public class DefaultFileLockManager
return lock; return lock;
} }
catch ( FileNotFoundException e )
catch (
FileNotFoundException e
)
{ {
throw new FileLockException( e.getMessage(), e ); throw new FileLockException( e.getMessage(), e );
} }
} }
private void createNewFileQuietly( File file )
{
try
{
file.createNewFile();
}
catch ( IOException e )
{
// skip that
}
}
@Override @Override
public void release( Lock lock ) public void release( Lock lock )
throws FileLockException throws FileLockException