mirror of https://github.com/sbt/sbt.git
Safer downloading from bootstraps
This commit is contained in:
parent
71878ce3e9
commit
75e53790bc
|
|
@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -168,6 +169,7 @@ public class Bootstrap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Random random = new Random();
|
||||||
for (final URL url : missingURLs) {
|
for (final URL url : missingURLs) {
|
||||||
completionService.submit(new Callable<URL>() {
|
completionService.submit(new Callable<URL>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -180,7 +182,10 @@ public class Bootstrap {
|
||||||
long lastModified = conn.getLastModified();
|
long lastModified = conn.getLastModified();
|
||||||
InputStream s = conn.getInputStream();
|
InputStream s = conn.getInputStream();
|
||||||
byte[] b = readFullySync(s);
|
byte[] b = readFullySync(s);
|
||||||
Files.write(dest.toPath(), b);
|
File tmpDest = new File(dest.getParentFile(), dest.getName() + "-" + random.nextInt());
|
||||||
|
tmpDest.deleteOnExit();
|
||||||
|
Files.write(tmpDest.toPath(), b);
|
||||||
|
Files.move(tmpDest.toPath(), dest.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
||||||
dest.setLastModified(lastModified);
|
dest.setLastModified(lastModified);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Error while downloading " + url + ": " + e.getMessage() + ", ignoring it");
|
System.err.println("Error while downloading " + url + ": " + e.getMessage() + ", ignoring it");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue