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-web/archiva-webdav/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-web/archiva-webdav/src/main')
2 files changed, 47 insertions, 23 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java index 5b76c7cfb..39cf9eaee 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java @@ -22,6 +22,10 @@ package org.apache.archiva.webdav; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; +import org.apache.archiva.common.filelock.FileLockException; +import org.apache.archiva.common.filelock.FileLockManager; +import org.apache.archiva.common.filelock.FileLockTimeoutException; +import org.apache.archiva.common.filelock.Lock; import org.apache.archiva.redback.components.taskqueue.TaskQueueException; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler; @@ -100,14 +104,16 @@ public class ArchivaDavResource public static final String COMPLIANCE_CLASS = "1, 2"; - private ArchivaTaskScheduler scheduler; + private final ArchivaTaskScheduler scheduler; + + private final FileLockManager fileLockManager; private Logger log = LoggerFactory.getLogger( ArchivaDavResource.class ); public ArchivaDavResource( String localResource, String logicalResource, ManagedRepository repository, DavSession session, ArchivaDavResourceLocator locator, DavResourceFactory factory, MimeTypes mimeTypes, List<AuditListener> auditListeners, - RepositoryArchivaTaskScheduler scheduler ) + RepositoryArchivaTaskScheduler scheduler, FileLockManager fileLockManager ) { this.localResource = new File( localResource ); this.logicalResource = logicalResource; @@ -122,15 +128,16 @@ public class ArchivaDavResource this.mimeTypes = mimeTypes; this.auditListeners = auditListeners; this.scheduler = scheduler; + this.fileLockManager = fileLockManager; } public ArchivaDavResource( String localResource, String logicalResource, ManagedRepository repository, String remoteAddr, String principal, DavSession session, ArchivaDavResourceLocator locator, DavResourceFactory factory, MimeTypes mimeTypes, - List<AuditListener> auditListeners, RepositoryArchivaTaskScheduler scheduler ) + List<AuditListener> auditListeners, RepositoryArchivaTaskScheduler scheduler , FileLockManager fileLockManager ) { this( localResource, logicalResource, repository, session, locator, factory, mimeTypes, auditListeners, - scheduler ); + scheduler, fileLockManager ); this.remoteAddr = remoteAddr; this.principal = principal; @@ -196,25 +203,37 @@ public class ArchivaDavResource outputContext.setContentType( mimeTypes.getMimeType( localResource.getName() ) ); } - if ( !isCollection() && outputContext.hasStream() ) + try { - FileInputStream is = null; - try + if ( !isCollection() && outputContext.hasStream() ) { - // TODO file lock library - // Write content to stream - is = new FileInputStream( localResource ); - IOUtils.copy( is, outputContext.getOutputStream() ); + Lock lock = fileLockManager.readFileLock( localResource ); + FileInputStream is = null; + try + { + // Write content to stream + is = new FileInputStream( lock.getFile() ); + IOUtils.copy( is, outputContext.getOutputStream() ); + } + finally + { + IOUtils.closeQuietly( is ); + fileLockManager.release( lock ); + } } - finally + else if ( outputContext.hasStream() ) { - IOUtils.closeQuietly( is ); + IndexWriter writer = new IndexWriter( this, localResource, logicalResource ); + writer.write( outputContext ); } } - else if ( outputContext.hasStream() ) + catch ( FileLockException e ) + { + throw new IOException( e.getMessage(), e ); + } + catch ( FileLockTimeoutException e ) { - IndexWriter writer = new IndexWriter( this, localResource, logicalResource ); - writer.write( outputContext ); + throw new IOException( e.getMessage(), e ); } } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index e24df205e..62b94ee25 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -27,6 +27,7 @@ import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.audit.Auditable; +import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; import org.apache.archiva.common.utils.PathUtil; @@ -178,6 +179,10 @@ public class ArchivaDavResourceFactory @Named( value = "archivaTaskScheduler#repository" ) private RepositoryArchivaTaskScheduler scheduler; + @Inject + @Named(value= "fileLockManager#default") + private FileLockManager fileLockManager; + private ApplicationContext applicationContext; @Inject @@ -268,7 +273,7 @@ public class ArchivaDavResourceFactory resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), locator.getResourcePath(), null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, - auditListeners, scheduler ); + auditListeners, scheduler, fileLockManager ); setHeaders( response, locator, resource ); return resource; } @@ -345,7 +350,7 @@ public class ArchivaDavResourceFactory resource = new ArchivaDavResource( metadataChecksum.getAbsolutePath(), logicalResource.getPath(), null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), - archivaLocator, this, mimeTypes, auditListeners, scheduler ); + archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager ); } } else @@ -384,7 +389,7 @@ public class ArchivaDavResourceFactory new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, - auditListeners, scheduler ); + auditListeners, scheduler, fileLockManager ); } catch ( RepositoryMetadataException r ) { @@ -440,7 +445,7 @@ public class ArchivaDavResourceFactory File resourceFile = new File( temporaryIndexDirectory, requestedFileName ); resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), requestedFileName, null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), - archivaLocator, this, mimeTypes, auditListeners, scheduler ); + archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager ); } else @@ -571,7 +576,7 @@ public class ArchivaDavResourceFactory resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), path, managedRepositoryContent.getRepository(), request.getRemoteAddr(), activePrincipal, request.getDavSession(), - archivaLocator, this, mimeTypes, auditListeners, scheduler ); + archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager ); if ( WebdavMethodUtil.isReadMethod( request.getMethod() ) ) { @@ -604,7 +609,7 @@ public class ArchivaDavResourceFactory managedRepositoryContent.getRepository(), request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, - auditListeners, scheduler ); + auditListeners, scheduler, fileLockManager ); } catch ( LayoutException e ) { @@ -726,7 +731,7 @@ public class ArchivaDavResourceFactory File resourceFile = new File( managedRepositoryContent.getRepoRoot(), logicalResource ); resource = new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource, managedRepositoryContent.getRepository(), davSession, archivaLocator, - this, mimeTypes, auditListeners, scheduler ); + this, mimeTypes, auditListeners, scheduler, fileLockManager ); resource.addLockManager( lockManager ); } |