diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-10-11 16:05:24 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-10-11 16:05:24 +0000 |
commit | bb9a82825b3c2eb30d6736895759eda550b6eed6 (patch) | |
tree | 1e25f9e67faa7e1be6872a498d51521fa9aaed33 /archiva-base/archiva-proxy | |
parent | 009ca8b1280e46d5be6228e85282e990428108ba (diff) | |
download | archiva-bb9a82825b3c2eb30d6736895759eda550b6eed6.tar.gz archiva-bb9a82825b3c2eb30d6736895759eda550b6eed6.zip |
Correcting logic for determining if the local maven-metadata.xml needs to be updated.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@583862 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-proxy')
-rw-r--r-- | archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 2f1cad9ae..4872427b2 100644 --- a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -170,7 +170,8 @@ public class DefaultRepositoryProxyConnectors File localFile = toLocalFile( repository, metadata ); Properties requestProperties = new Properties(); - boolean hasFetched = false; + boolean metadataNeedsUpdating = false; + long originalTimestamp = getLastModified( localFile ); List<ProxyConnector> connectors = getProxyConnectors( repository ); for ( ProxyConnector connector : connectors ) @@ -179,17 +180,21 @@ public class DefaultRepositoryProxyConnectors String targetPath = metadataTools.toPath( metadata ); File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - File downloadedFile = transferFile( connector, targetRepository, targetPath, localRepoFile, - requestProperties ); + long originalMetadataTimestamp = getLastModified( localRepoFile ); + transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); - if ( fileExists( downloadedFile ) ) + if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) { - getLogger().debug( "Successfully transfered: " + downloadedFile.getAbsolutePath() ); - hasFetched = true; + metadataNeedsUpdating = true; } } - if ( hasFetched || fileExists( localFile ) ) + if ( hasBeenUpdated( localFile, originalTimestamp ) ) + { + metadataNeedsUpdating = true; + } + + if ( metadataNeedsUpdating ) { try { @@ -228,6 +233,27 @@ public class DefaultRepositoryProxyConnectors return null; } + private long getLastModified( File file ) + { + if ( !file.exists() || !file.isFile() ) + { + return 0; + } + + return file.lastModified(); + } + + private boolean hasBeenUpdated( File file, long originalLastModified ) + { + if ( !file.exists() || !file.isFile() ) + { + return false; + } + + long currentLastModified = getLastModified( file ); + return ( currentLastModified > originalLastModified ); + } + /** * Fetch from the proxies a metadata.xml file for the groupId:artifactId metadata contents. * @@ -239,7 +265,8 @@ public class DefaultRepositoryProxyConnectors File localFile = toLocalFile( repository, metadata ); Properties requestProperties = new Properties(); - boolean hasFetched = false; + boolean metadataNeedsUpdating = false; + long originalTimestamp = getLastModified( localFile ); List<ProxyConnector> connectors = getProxyConnectors( repository ); for ( ProxyConnector connector : connectors ) @@ -248,17 +275,21 @@ public class DefaultRepositoryProxyConnectors String targetPath = metadataTools.toPath( metadata ); File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - File downloadedFile = transferFile( connector, targetRepository, targetPath, localRepoFile, - requestProperties ); + long originalMetadataTimestamp = getLastModified( localRepoFile ); + transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); - if ( fileExists( downloadedFile ) ) + if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) { - getLogger().debug( "Successfully transfered: " + downloadedFile.getAbsolutePath() ); - hasFetched = true; + metadataNeedsUpdating = true; } } - if ( hasFetched || fileExists( localFile ) ) + if ( hasBeenUpdated( localFile, originalTimestamp ) ) + { + metadataNeedsUpdating = true; + } + + if ( metadataNeedsUpdating ) { try { @@ -428,7 +459,6 @@ public class DefaultRepositoryProxyConnectors transferChecksum( wagon, remoteRepository, remotePath, localFile, ".sha1" ); transferChecksum( wagon, remoteRepository, remotePath, localFile, ".md5" ); - } } catch ( ResourceDoesNotExistException e ) |