mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
Self correct if the zip file is corrupt.
This commit is contained in:
parent
5b38419aed
commit
1f3fb8f3eb
1 changed files with 38 additions and 22 deletions
|
@ -12,6 +12,7 @@ import java.util.Enumeration;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class Main {
|
||||
|
@ -96,18 +97,16 @@ public class Main {
|
|||
getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar");
|
||||
if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) {
|
||||
if (!Files.exists(localZipFile)) {
|
||||
String fullUrl = URL + "/" + fileName;
|
||||
download(fullUrl, localZipFile.toFile());
|
||||
if (!Files.exists(localZipFile)) {
|
||||
log(2, localZipFile + " downloaded, extracting it");
|
||||
} else {
|
||||
log(2, localZipFile + " already exists, extracting it");
|
||||
}
|
||||
download(fileName, localZipFile.toFile());
|
||||
}
|
||||
|
||||
//
|
||||
// Extract all the zip files
|
||||
//
|
||||
boolean success = false;
|
||||
int retries = 0;
|
||||
while (! success && retries < 2) {
|
||||
try {
|
||||
ZipFile zipFile = new ZipFile(localZipFile.toFile());
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
File outputDirectory = new File(DISTRIBUTIONS_DIR);
|
||||
|
@ -124,6 +123,15 @@ public class Main {
|
|||
Files.copy(zipFile.getInputStream(entry), dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
} catch (ZipException e) {
|
||||
retries++;
|
||||
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
|
||||
error("The file is probably corrupt, downloading it again");
|
||||
Files.delete(localZipFile);
|
||||
download(fileName, localZipFile.toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -153,7 +161,9 @@ public class Main {
|
|||
|
||||
private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" };
|
||||
|
||||
private void download(String fileUrl, File file) throws IOException {
|
||||
private void download(String fn, File file) throws IOException {
|
||||
String fileUrl = URL + "/" + fn;
|
||||
|
||||
URL url = new URL(fileUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
int responseCode = httpConn.getResponseCode();
|
||||
|
@ -214,6 +224,12 @@ public class Main {
|
|||
error("No file to download. Server replied HTTP code: " + responseCode);
|
||||
}
|
||||
httpConn.disconnect();
|
||||
|
||||
if (! file.exists()) {
|
||||
log(2, file + " downloaded, extracting it");
|
||||
} else {
|
||||
log(2, file + " already exists, extracting it");
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFile(File file, String text) throws IOException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue