mirror of https://github.com/apache/maven.git
o changing the strategy for downloading to make File.renameTo workable.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162964 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
668bcd6ac8
commit
d0be8d9bf8
|
@ -31,12 +31,14 @@ import org.apache.maven.wagon.authorization.AuthorizationException;
|
||||||
import org.apache.maven.wagon.observers.ChecksumObserver;
|
import org.apache.maven.wagon.observers.ChecksumObserver;
|
||||||
import org.codehaus.plexus.PlexusConstants;
|
import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.context.Context;
|
import org.codehaus.plexus.context.Context;
|
||||||
import org.codehaus.plexus.context.ContextException;
|
import org.codehaus.plexus.context.ContextException;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -134,7 +136,7 @@ public class DefaultWagonManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
temp = File.createTempFile( "wagon", "tmp" );
|
temp = new File( destination + ".tmp" );
|
||||||
|
|
||||||
temp.deleteOnExit();
|
temp.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
@ -149,7 +151,6 @@ public class DefaultWagonManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
Wagon wagon = getWagon( repository.getProtocol() );
|
Wagon wagon = getWagon( repository.getProtocol() );
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -165,8 +166,6 @@ public class DefaultWagonManager
|
||||||
|
|
||||||
wagon.get( path( artifact ), temp );
|
wagon.get( path( artifact ), temp );
|
||||||
|
|
||||||
transfered = true;
|
|
||||||
|
|
||||||
wagon.disconnect();
|
wagon.disconnect();
|
||||||
|
|
||||||
releaseWagon( wagon );
|
releaseWagon( wagon );
|
||||||
|
@ -176,6 +175,8 @@ public class DefaultWagonManager
|
||||||
{
|
{
|
||||||
// This one we will eat when looking through remote repositories
|
// This one we will eat when looking through remote repositories
|
||||||
// because we want to cycle through them all before squawking.
|
// because we want to cycle through them all before squawking.
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
catch ( UnsupportedProtocolException e )
|
catch ( UnsupportedProtocolException e )
|
||||||
{
|
{
|
||||||
|
@ -197,26 +198,37 @@ public class DefaultWagonManager
|
||||||
{
|
{
|
||||||
throw new TransferFailedException( "Release of wagon failed: ", e );
|
throw new TransferFailedException( "Release of wagon failed: ", e );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( transfered )
|
|
||||||
{
|
|
||||||
if ( !destination.getParentFile().exists() )
|
if ( !destination.getParentFile().exists() )
|
||||||
{
|
{
|
||||||
destination.getParentFile().mkdirs();
|
destination.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
transfered = temp.renameTo( destination );
|
// The temporary file is named destination + ".tmp" and is done this way to ensure
|
||||||
|
// that the temporary file is in the same file system as the destination because the
|
||||||
|
// File.renameTo operation doesn't really work across file systems. So we will attempt
|
||||||
|
// to do a File.renameTo for efficiency and atomicity, if this fails then we will use
|
||||||
|
// a brute force copy and delete the temporary file.
|
||||||
|
|
||||||
|
if ( !temp.renameTo( destination ) )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.copyFile( temp, destination );
|
||||||
|
|
||||||
|
temp.delete();
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new TransferFailedException( "Error copying temporary file to the final destination: ", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
temp.delete();
|
|
||||||
|
|
||||||
throw new TransferFailedException( "Resource doesn't exist in any remote repository" );
|
throw new TransferFailedException( "Resource doesn't exist in any remote repository" );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void contextualize( Context context )
|
public void contextualize( Context context )
|
||||||
throws ContextException
|
throws ContextException
|
||||||
|
|
Loading…
Reference in New Issue