diff options
author | Olivier Lamy <olamy@apache.org> | 2013-12-13 04:46:36 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-12-13 04:46:36 +0000 |
commit | 06cb9ea4f943146390c6942b813d2cdb11bfadfe (patch) | |
tree | 2f5ae62d15b3994f05101b66bd48250ca0011db2 /archiva-modules/archiva-base/archiva-filelock/src/main | |
parent | c3ba717d4cd6aa3c3825fb845a4650ca0d67f37e (diff) | |
download | archiva-06cb9ea4f943146390c6942b813d2cdb11bfadfe.tar.gz archiva-06cb9ea4f943146390c6942b813d2cdb11bfadfe.zip |
[MRM-1702] use the fileLockLManager in the code with possible race condition
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1550636 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-filelock/src/main')
2 files changed, 49 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 812ffe9a1..4adf69b4f 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 @@ -33,7 +33,7 @@ import java.util.concurrent.ConcurrentMap; /** * @author Olivier Lamy */ -@Service("fileLockManager#default") +@Service( "fileLockManager#default" ) public class DefaultFileLockManager implements FileLockManager { @@ -45,6 +45,7 @@ public class DefaultFileLockManager private int timeout = 0; + @Override public Lock readFileLock( File file ) throws FileLockException, FileLockTimeoutException @@ -56,7 +57,7 @@ public class DefaultFileLockManager } StopWatch stopWatch = new StopWatch(); boolean acquired = false; - + mkdirs( file.getParentFile() ); try { Lock lock = new Lock( file, false ); @@ -108,6 +109,8 @@ public class DefaultFileLockManager return new Lock( file ); } + mkdirs( file.getParentFile() ); + StopWatch stopWatch = new StopWatch(); boolean acquired = false; @@ -176,6 +179,36 @@ public class DefaultFileLockManager } } + private boolean mkdirs( File directory ) + { + if ( directory == null ) + { + return false; + } + + if ( directory.exists() ) + { + return false; + } + if ( directory.mkdir() ) + { + return true; + } + + File canonDir = null; + try + { + canonDir = directory.getCanonicalFile(); + } + catch ( IOException e ) + { + return false; + } + + File parentDir = canonDir.getParentFile(); + return ( parentDir != null && ( mkdirs( parentDir ) || parentDir.exists() ) && canonDir.mkdir() ); + } + public int getTimeout() { return timeout; diff --git a/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/FileLockManager.java b/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/FileLockManager.java index bf18292ae..5b7eeed38 100644 --- a/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/FileLockManager.java +++ b/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/FileLockManager.java @@ -27,9 +27,23 @@ import java.io.FileNotFoundException; */ public interface FileLockManager { + /** + * + * @param file + * @return + * @throws FileLockException + * @throws FileLockTimeoutException + */ Lock writeFileLock( File file ) throws FileLockException, FileLockTimeoutException; + /** + * + * @param file + * @return + * @throws FileLockException + * @throws FileLockTimeoutException + */ Lock readFileLock( File file ) throws FileLockException, FileLockTimeoutException; |