Skip to content

Commit

Permalink
Use FileUtils.deleteFileOrDirectory instead of File.delete.
Browse files Browse the repository at this point in the history
On OSX the app is a directory and it was failing.

Wrap IOException as cause into the IllegalStateException.
Add error log.

Change redirectError(ProcessBuilder.Redirect.DISCARD) to redirectError(ProcessBuilder.Redirect.INHERIT) to get error printed.

Reduce timeout for extract from 1 min to 30 sec. It usually takes just 1-2 seconds.
  • Loading branch information
HenrikJannsen committed Dec 30, 2022
1 parent 68429cc commit 996178d
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.common.util.FileUtils;
import bisq.common.util.OsUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -31,6 +32,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

@Slf4j
public class ElectrumBinaryExtractor {

public static final String LINUX_BINARY_SUFFIX = "AppImage";
Expand Down Expand Up @@ -113,9 +115,11 @@ private File extractFileWithSuffixFromStream(InputStream inputStream, String fil
private void deleteElectrumAppFileIfExisting() {
File electrumAppInDataDir = new File(destDir, "Electrum.app");
if (electrumAppInDataDir.exists()) {
boolean isSuccess = electrumAppInDataDir.delete();
if (!isSuccess) {
throw new IllegalStateException("Couldn't delete old Electrum.app");
try {
FileUtils.deleteFileOrDirectory(electrumAppInDataDir);
} catch (IOException e) {
log.error("Could not delete " + electrumAppInDataDir, e);
throw new IllegalStateException("Couldn't delete old Electrum.app", e);
}
}
}
Expand All @@ -126,19 +130,19 @@ private void copyZipFromResourcesToDataDir(InputStream inputStream) {
Files.copy(inputStream, zipFileInDataDir.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new ElectrumExtractionFailedException(
"Couldn't copy Electrum binaries zip file from resources to the data directory."
"Couldn't copy Electrum binaries zip file from resources to the data directory.", e
);
}
}

private void unpackZipFileWithUnzipCommand() {
try {
Process extractProcess = new ProcessBuilder("unzip", ARCHIVE_FILENAME)
Process extractProcess = new ProcessBuilder("unzip", "-o", ARCHIVE_FILENAME)
.directory(destDir)
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
.redirectError(ProcessBuilder.Redirect.DISCARD)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start();
boolean isSuccess = extractProcess.waitFor(1, TimeUnit.MINUTES);
boolean isSuccess = extractProcess.waitFor(30, TimeUnit.SECONDS);
if (!isSuccess) {
throw new ElectrumExtractionFailedException("Could not copy Electrum.app to data directory.");
}
Expand Down

0 comments on commit 996178d

Please sign in to comment.