From caab5531c0491bf07d6354c932d86af844c4c5c0 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 18 Jul 2008 08:16:24 +0000 Subject: [PATCH] [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 --- .../archiva/policies/ChecksumPolicy.java | 5 +++ .../DefaultRepositoryProxyConnectors.java | 31 ++++++++++++---- .../proxy/ManagedDefaultTransferTest.java | 37 +++++++++++++++++++ .../get-default-layout-present-1.0.jar.asc | 7 ++++ .../get-default-layout-present-1.0.jar.asc | 1 + 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 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 create mode 100644 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 diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java index 76b5db51d..fe89822fe 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/ChecksumPolicy.java @@ -80,6 +80,11 @@ public class ChecksumPolicy public void applyPolicy( String policySetting, Properties request, File localFile ) throws PolicyViolationException, PolicyConfigurationException { + if ( "resource".equals( request.getProperty( "filetype" ) ) ) + { + return; + } + if ( !options.contains( policySetting ) ) { // Not a valid code. 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 ); } @@ -117,6 +120,40 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + /** + * The attempt here should result in no file being transferred. + *

+ * 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 ); + } + /** *

* Request a file, that exists locally, and remotely. 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! -- 2.39.5