git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@675174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nicolas De Loof 2008-07-09 14:00:22 +00:00
parent a693bc6872
commit 15b6ddae0b
4 changed files with 43 additions and 39 deletions

View File

@ -169,7 +169,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
File downloadedFile = File downloadedFile =
transferFile( connector, targetRepository, targetPath, localFile, requestProperties ); transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties );
if ( fileExists( downloadedFile ) ) if ( fileExists( downloadedFile ) )
{ {
@ -230,7 +230,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); transferFile( connector, targetRepository, targetPath, repository, localRepoFile, requestProperties );
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
{ {
@ -348,7 +348,7 @@ public class DefaultRepositoryProxyConnectors
long originalMetadataTimestamp = getLastModified( localRepoFile ); long originalMetadataTimestamp = getLastModified( localRepoFile );
try try
{ {
transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); transferFile( connector, targetRepository, targetPath, repository, localRepoFile, requestProperties );
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
{ {
@ -487,6 +487,7 @@ public class DefaultRepositoryProxyConnectors
* @param connector the connector configuration to use. * @param connector the connector configuration to use.
* @param remoteRepository the remote repository get the resource from. * @param remoteRepository the remote repository get the resource from.
* @param remotePath the path in the remote repository to the resource to get. * @param remotePath the path in the remote repository to the resource to get.
* @param repository the managed repository that will hold the file
* @param localFile the local file to place the downloaded resource into * @param localFile the local file to place the downloaded resource into
* @param requestProperties the request properties to utilize for policy handling. * @param requestProperties the request properties to utilize for policy handling.
* @return the local file that was downloaded, or null if not downloaded. * @return the local file that was downloaded, or null if not downloaded.
@ -496,7 +497,7 @@ public class DefaultRepositoryProxyConnectors
* @throws ProxyException if transfer was unsuccessful. * @throws ProxyException if transfer was unsuccessful.
*/ */
private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile, Properties requestProperties ) ManagedRepositoryContent repository, File localFile, Properties requestProperties )
throws ProxyException, NotModifiedException throws ProxyException, NotModifiedException
{ {
String url = remoteRepository.getURL().getUrl(); String url = remoteRepository.getURL().getUrl();
@ -560,10 +561,10 @@ public class DefaultRepositoryProxyConnectors
boolean connected = connectToRepository( connector, wagon, remoteRepository ); boolean connected = connectToRepository( connector, wagon, remoteRepository );
if ( connected ) if ( connected )
{ {
localFile = transferSimpleFile( wagon, remoteRepository, remotePath, localFile ); localFile = transferSimpleFile( wagon, remoteRepository, remotePath, repository, localFile );
transferChecksum( wagon, remoteRepository, remotePath, localFile, ".sha1" ); transferChecksum( wagon, remoteRepository, remotePath, repository, localFile, ".sha1" );
transferChecksum( wagon, remoteRepository, remotePath, localFile, ".md5" ); transferChecksum( wagon, remoteRepository, remotePath, repository, localFile, ".md5" );
} }
} }
catch ( NotFoundException e ) catch ( NotFoundException e )
@ -627,12 +628,13 @@ public class DefaultRepositoryProxyConnectors
* @param wagon the wagon instance (should already be connected) to use. * @param wagon the wagon instance (should already be connected) to use.
* @param remoteRepository the remote repository to transfer from. * @param remoteRepository the remote repository to transfer from.
* @param remotePath the remote path to the resource to get. * @param remotePath the remote path to the resource to get.
* @param repository the managed repository that will hold the file
* @param localFile the local file that should contain the downloaded contents * @param localFile the local file that should contain the downloaded contents
* @param type the type of checksum to transfer (example: ".md5" or ".sha1") * @param type the type of checksum to transfer (example: ".md5" or ".sha1")
* @throws ProxyException if copying the downloaded file into place did not succeed. * @throws ProxyException if copying the downloaded file into place did not succeed.
*/ */
private void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile, String type ) ManagedRepositoryContent repository, File localFile, String type )
throws ProxyException throws ProxyException
{ {
String url = remoteRepository.getURL().getUrl() + remotePath; String url = remoteRepository.getURL().getUrl() + remotePath;
@ -646,7 +648,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
File hashFile = new File( localFile.getAbsolutePath() + type ); File hashFile = new File( localFile.getAbsolutePath() + type );
transferSimpleFile( wagon, remoteRepository, remotePath + type, hashFile ); transferSimpleFile( wagon, remoteRepository, remotePath + type, repository, hashFile );
log.debug( "Checksum" + type + " Downloaded: " + hashFile ); log.debug( "Checksum" + type + " Downloaded: " + hashFile );
} }
catch ( NotFoundException e ) catch ( NotFoundException e )
@ -675,13 +677,14 @@ public class DefaultRepositoryProxyConnectors
* @param wagon the wagon instance to use. * @param wagon the wagon instance to use.
* @param remoteRepository the remote repository to use * @param remoteRepository the remote repository to use
* @param remotePath the remote path to attempt to get * @param remotePath the remote path to attempt to get
* @param repository the managed repository that will hold the file
* @param localFile the local file to save to * @param localFile the local file to save to
* @return The local file that was transfered. * @return The local file that was transfered.
* @throws ProxyException if there was a problem moving the downloaded file into place. * @throws ProxyException if there was a problem moving the downloaded file into place.
* @throws WagonException if there was a problem tranfering the file. * @throws WagonException if there was a problem tranfering the file.
*/ */
private File transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private File transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile ) ManagedRepositoryContent repository, File localFile )
throws ProxyException throws ProxyException
{ {
assert ( remotePath != null ); assert ( remotePath != null );
@ -691,8 +694,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
localFile.getParentFile().mkdirs(); temp = File.createTempFile(localFile.getName() + ".", null, new File( repository.getRepoRoot() ));
temp = File.createTempFile(localFile.getName() + ".", null, localFile.getParentFile());
boolean success = false; boolean success = false;
@ -849,6 +851,7 @@ public class DefaultRepositoryProxyConnectors
throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() ); throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() );
} }
target.getParentFile().mkdirs();
if ( !temp.renameTo( target ) ) if ( !temp.renameTo( target ) )
{ {
log.warn( "Unable to rename tmp file to its final name... resorting to copy command." ); log.warn( "Unable to rename tmp file to its final name... resorting to copy command." );

View File

@ -540,6 +540,9 @@ public abstract class AbstractProxyTestCase
FileUtils.deleteDirectory( destDir ); FileUtils.deleteDirectory( destDir );
} }
// Make the destination dir.
destDir.mkdirs();
// Test the source dir. // Test the source dir.
if ( !sourceDir.exists() ) if ( !sourceDir.exists() )
{ {
@ -555,9 +558,6 @@ public abstract class AbstractProxyTestCase
fail( "Unable to setup testable managed repository, source is not a directory: " + sourceDir ); fail( "Unable to setup testable managed repository, source is not a directory: " + sourceDir );
} }
// Make the destination dir.
destDir.mkdirs();
// Copy directory structure. // Copy directory structure.
copyDirectoryStructure( sourceDir, destDir ); copyDirectoryStructure( sourceDir, destDir );
} }

View File

@ -138,6 +138,7 @@ public class CacheFailuresTransferTest
throws Exception throws Exception
{ {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );

View File

@ -551,7 +551,7 @@ public class ErrorHandlingTest
private File createExpectedTempFile( File expectedFile ) private File createExpectedTempFile( File expectedFile )
{ {
return new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ).getAbsoluteFile(); return new File( managedDefaultDir, expectedFile.getName() + ".tmp" ).getAbsoluteFile();
} }
private void confirmSingleFailure( String path, String id ) private void confirmSingleFailure( String path, String id )