diff options
author | Brett Porter <brett@apache.org> | 2008-07-18 08:16:24 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2008-07-18 08:16:24 +0000 |
commit | caab5531c0491bf07d6354c932d86af844c4c5c0 (patch) | |
tree | 9d4a3fc3d0f21c9c6705f1d98df9a3e4f211af58 /archiva-modules/archiva-base/archiva-proxy | |
parent | 28e545b65a3079ca6b09d691c2ebb0d64d23254f (diff) | |
download | archiva-caab5531c0491bf07d6354c932d86af844c4c5c0.tar.gz archiva-caab5531c0491bf07d6354c932d86af844c4c5c0.zip |
[MRM-876] don't grab the remote file if it exists in the managed repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@677852 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-proxy')
4 files changed, 69 insertions, 7 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 7f5a1e1d2..3604bc20b 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -160,7 +160,8 @@ public class DefaultRepositoryProxyConnectors try { File downloadedFile = - transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties ); + transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties, + true ); if ( fileExists( downloadedFile ) ) { @@ -199,6 +200,12 @@ public class DefaultRepositoryProxyConnectors public File fetchFromProxies( ManagedRepositoryContent repository, String path ) { File localFile = new File( repository.getRepoRoot(), path ); + + // no update policies for these paths + if ( localFile.exists() ) + { + return null; + } Properties requestProperties = new Properties(); requestProperties.setProperty( "filetype", "resource" ); @@ -215,7 +222,8 @@ public class DefaultRepositoryProxyConnectors try { File downloadedFile = - transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties ); + transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties, + false ); if ( fileExists( downloadedFile ) ) { @@ -266,7 +274,8 @@ public class DefaultRepositoryProxyConnectors try { - transferFile( connector, targetRepository, targetPath, repository, localRepoFile, requestProperties ); + transferFile( connector, targetRepository, targetPath, repository, localRepoFile, requestProperties, + true ); if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) { @@ -378,7 +387,8 @@ public class DefaultRepositoryProxyConnectors long originalMetadataTimestamp = getLastModified( localRepoFile ); try { - transferFile( connector, targetRepository, targetPath, repository, localRepoFile, requestProperties ); + transferFile( connector, targetRepository, targetPath, repository, localRepoFile, requestProperties, + true ); if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) { @@ -520,6 +530,7 @@ public class DefaultRepositoryProxyConnectors * @param repository the managed repository that will hold the file * @param localFile the local file to place the downloaded resource into * @param requestProperties the request properties to utilize for policy handling. + * @param executeConsumers whether to execute the consumers after proxying * @return the local file that was downloaded, or null if not downloaded. * @throws NotFoundException if the file was not found on the remote repository. * @throws NotModifiedException if the localFile was present, and the resource was present on remote repository, @@ -527,7 +538,8 @@ public class DefaultRepositoryProxyConnectors * @throws ProxyException if transfer was unsuccessful. */ private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, File localFile, Properties requestProperties ) + ManagedRepositoryContent repository, File localFile, Properties requestProperties, + boolean executeConsumers ) throws ProxyException, NotModifiedException { String url = remoteRepository.getURL().getUrl(); @@ -593,6 +605,8 @@ public class DefaultRepositoryProxyConnectors { localFile = transferSimpleFile( wagon, remoteRepository, remotePath, repository, localFile ); + // TODO: these should be used to validate the download based on the policies, not always downloaded to + // save on connections since md5 is rarely used transferChecksum( wagon, remoteRepository, remotePath, repository, localFile, ".sha1" ); transferChecksum( wagon, remoteRepository, remotePath, repository, localFile, ".md5" ); } @@ -643,8 +657,11 @@ public class DefaultRepositoryProxyConnectors return null; } - // Just-in-time update of the index and database by executing the consumers for this artifact - consumers.executeConsumers( connector.getSourceRepository().getRepository(), localFile ); + if ( executeConsumers ) + { + // Just-in-time update of the index and database by executing the consumers for this artifact + consumers.executeConsumers( connector.getSourceRepository().getRepository(), localFile ); + } // Everything passes. return localFile; diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java index 32f6db1a5..878e96d50 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java @@ -84,6 +84,9 @@ public class ManagedDefaultTransferTest File sourceFile = new File( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, sourceFile ); + assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".sha1" ).exists() ); + assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".md5" ).exists() ); + assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".asc" ).exists() ); assertNoTempFiles( expectedFile ); } @@ -118,6 +121,40 @@ public class ManagedDefaultTransferTest } /** + * The attempt here should result in no file being transferred. + * <p/> + * The file exists locally, and the policy is ONCE. + * + * @throws Exception + */ + public void testGetDefaultLayoutAlreadyPresentPassthrough() + throws Exception + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc"; + setupTestableManagedRepository( path ); + + File expectedFile = new File( managedDefaultDir, path ); + File remoteFile = new File( REPOPATH_PROXIED1, path ); + + assertTrue( expectedFile.exists() ); + + // Set the managed File to be newer than local. + setManagedOlderThanRemote( expectedFile, remoteFile ); + long originalModificationTime = expectedFile.lastModified(); + + // Configure Connector (usually done within archiva.xml configuration) + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE, + CachedFailuresPolicy.NO ); + + // Attempt the proxy fetch. + File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); + + assertNotDownloaded( downloadedFile ); + assertNotModified( expectedFile, originalModificationTime ); + assertNoTempFiles( expectedFile ); + } + + /** * <p> * Request a file, that exists locally, and remotely. * </p> diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc b/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc new file mode 100644 index 000000000..c3f4c234e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc @@ -0,0 +1,7 @@ +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.8 (Darwin) + +iEYEABECAAYFAkiAQxIACgkQTusOMqfRa9T2xACfcvI2fjAXoAHGwJm0zXPJ2rWW +OPoAn23dSOEJhyNUY2hgUlH2wSQiADeP +=ZOwh +-----END PGP SIGNATURE----- diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc b/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc new file mode 100644 index 000000000..07bf0cfd6 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc @@ -0,0 +1 @@ +THIS IS THE WRONG CONTENT! |