now we unzip downloaded autoupdate zip file in two steps:
1. all files except `rusefi_autouppdate.jar` before new class loader preparation 2. `rusefi_autouppdate.jar` after new class loader preparation (closes #6777)
This commit is contained in:
parent
f15bc18f73
commit
1f131cd5ce
|
@ -25,6 +25,8 @@ import java.util.Optional;
|
|||
import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
import static com.rusefi.core.FindFileHelper.findSrecFile;
|
||||
|
@ -105,16 +107,18 @@ public class Autoupdate {
|
|||
}
|
||||
downloadedAutoupdateFile.ifPresent(autoupdateFile -> {
|
||||
try {
|
||||
FileUtil.unzip(autoupdateFile.zipFileName, new File(".."));
|
||||
// We cannot unzip rusefi_autoupdate.jar file because we need the old one to prepare class loader below
|
||||
// (otherwise we get `ZipFile invalid LOC header (bad signature)` exception, see #6777)
|
||||
FileUtil.unzip(autoupdateFile.zipFileName, new File(".."), isRusefiAutoupdateJar.negate());
|
||||
final String srecFile = findSrecFile();
|
||||
new File(srecFile == null ? FindFileHelper.FIRMWARE_BIN_FILE : srecFile)
|
||||
.setLastModified(autoupdateFile.lastModified);
|
||||
} catch (IOException e) {
|
||||
log.error("Error unzipping bundle: " + e);
|
||||
log.error("Error unzipping bundle without rusefi_autoupdate.jar: " + e);
|
||||
if (!AutoupdateUtil.runHeadless) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Error unzipping bundle " + e,
|
||||
"Error unzipping bundle without rusefi_autoupdate.jar: " + e,
|
||||
"Error",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
|
@ -122,9 +126,28 @@ public class Autoupdate {
|
|||
}
|
||||
});
|
||||
final URLClassLoader jarClassLoader = prepareClassLoaderToStartConsole();
|
||||
downloadedAutoupdateFile.ifPresent(autoupdateFile -> {
|
||||
try {
|
||||
// We've already prepared class loader, so now we can unzip rusefi_autoupdate.jar file (#6777)
|
||||
FileUtil.unzip(autoupdateFile.zipFileName, new File(".."), isRusefiAutoupdateJar);
|
||||
} catch (IOException e) {
|
||||
log.error("Error unzipping rusefi_autoupdate.jar from bundle: " + e);
|
||||
if (!AutoupdateUtil.runHeadless) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Error unzipping rusefi_autoupdate.jar from bundle: " + e,
|
||||
"Error",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
startConsole(args, jarClassLoader);
|
||||
}
|
||||
|
||||
private static final Predicate<ZipEntry> isRusefiAutoupdateJar =
|
||||
zipEntry -> "console/rusefi_autoupdate.jar".equals(zipEntry.getName());
|
||||
|
||||
private static Optional<DownloadedAutoupdateFileInfo> doDownload(
|
||||
final BundleUtil.BundleInfo bundleInfo,
|
||||
final UpdateMode mode
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
@ -14,7 +15,11 @@ import java.util.zip.ZipInputStream;
|
|||
public class FileUtil {
|
||||
public static final String RUSEFI_SETTINGS_FOLDER = System.getProperty("user.home") + File.separator + ".rusEFI";
|
||||
|
||||
public static void unzip(String zipFileName, File destDir) throws IOException {
|
||||
public static void unzip(
|
||||
final String zipFileName,
|
||||
final File destDir,
|
||||
final Predicate<ZipEntry> filter
|
||||
) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName));
|
||||
ZipEntry zipEntry = zis.getNextEntry();
|
||||
|
@ -24,6 +29,7 @@ public class FileUtil {
|
|||
* apache commons compress does
|
||||
* https://stackoverflow.com/questions/1050560/maintain-file-permissions-when-extracting-from-a-zip-file-using-jdk-5-api
|
||||
*/
|
||||
if (filter.test(zipEntry)) {
|
||||
File newFile = newFile(destDir, zipEntry);
|
||||
if (zipEntry.isDirectory()) {
|
||||
if (!newFile.isDirectory()) {
|
||||
|
@ -34,6 +40,7 @@ public class FileUtil {
|
|||
} else {
|
||||
unzipFile(buffer, zis, newFile);
|
||||
}
|
||||
}
|
||||
zipEntry = zis.getNextEntry();
|
||||
}
|
||||
zis.closeEntry();
|
||||
|
|
Loading…
Reference in New Issue