Permalink
Browse files

o Do not download all checksum files immediately

  • Loading branch information...
1 parent 57d04c2 commit 1e14befb841bbd124d2e1e92f0410c60147b4da4 @nabcos nabcos committed Feb 11, 2011
@@ -15,12 +15,13 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-
+import java.util.concurrent.TimeUnit;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.spi.connector.ArtifactDownload;
import org.sonatype.aether.spi.connector.MetadataDownload;
@@ -53,6 +54,8 @@
private ProgressingFileBodyConsumer consumer;
+ private Iterator<String> checksumAlgoIterator;
+
public SimpleGetTask( ArtifactDownload download, ConnectorConfiguration configuration )
{
this( configuration, new TransferWrapper( download ) );
@@ -95,10 +98,7 @@ public void run()
futureResponse =
derivedClient.get( consumer );
- for ( String algo : configuration.getChecksumAlgos().keySet() )
- {
- checksumDownloads.put( algo, downloadChecksum( algo ) );
- }
+ downloadChecksum( configuration.getChecksumAlgos().keySet().iterator().next() );
}
}
catch ( Exception e )
@@ -142,10 +142,20 @@ private void cancelLeftoverChecksumDownloads()
for ( Entry<String, Future<Response>> entry : checksumDownloads.entrySet() )
{
Future<Response> future = entry.getValue();
- if ( !future.isDone() )
+ try {
+ // see if download is done "soon"
+ Response response = future.get( 1, TimeUnit.SECONDS );
+ handleResponseCode( url, response.getStatusCode(), response.getStatusText() );
+
+ String extension = configuration.getChecksumAlgos().get( entry.getKey() );
+ configuration.getFileProcessor().move( extensionFile( extension + ".tmp" ), extensionFile( extension ) );
+ }
+ catch ( Exception e )
{
+ // we are only cleaning up here, don't propagate
future.cancel( true );
- extensionFile( entry.getKey() + ".tmp" ).delete();
+ File tmpfile = extensionFile( entry.getKey() + ".tmp" );
+ tmpfile.delete();
}
}
}
@@ -184,7 +194,6 @@ public void processResponse()
verifyChecksum();
configuration.getFileProcessor().move( tmpFile(), transfer.getFile() );
-
}
long transferredBytes = consumer == null ? 0 : consumer.getTransferredBytes();
@@ -257,7 +266,16 @@ private void retrieveChecksum( String algorithm )
throws Exception
{
Future<Response> future = checksumDownloads.get( algorithm );
+
+ if ( future == null )
+ {
+ future = downloadChecksum( algorithm );
+ }
+
Response response = future.get();
+
+ checksumDownloads.remove( algorithm );
+
handleResponseCode( url, response.getStatusCode(), response.getStatusText() );
String extension = configuration.getChecksumAlgos().get( algorithm );
@@ -278,6 +296,8 @@ private void retrieveChecksum( String algorithm )
Future<Response> future = derivedClient.get( target );
+ checksumDownloads.put( algorithm, future );
+
return future;
}

0 comments on commit 1e14bef

Please sign in to comment.