install monero bins to local app directories and exclude from backup

This commit is contained in:
woodser 2024-06-22 08:35:08 -04:00
parent f4fe8997a6
commit 4e13aab53d
5 changed files with 27 additions and 12 deletions

View file

@ -532,6 +532,7 @@ configure(project(':core')) {
ext.downloadAndVerifyDependencies = { String archiveURL, String archiveSHA256, File destinationArchiveFile ->
ext.dependencyDownloadedAndVerified = false
// if archive exists, check to see if its already up to date
if (destinationArchiveFile.exists()) {
println "Verifying existing archive ${destinationArchiveFile}"
@ -545,14 +546,15 @@ configure(project(':core')) {
}
}
// download archives
println "Downloading ${archiveURL}"
ant.get(src: archiveURL, dest: destinationArchiveFile)
println 'Download saved to ' + destinationArchiveFile
// verify checksum
println 'Verifying checksum for downloaded binary ...'
ant.archiveHash = archiveSHA256
// use a different verifyProperty name from existing verification or it will always fail
ant.checksum(file: destinationArchiveFile, algorithm: 'SHA-256', property: '${archiveHash}', verifyProperty: 'downloadedHashMatches')
ant.checksum(file: destinationArchiveFile, algorithm: 'SHA-256', property: '${archiveHash}', verifyProperty: 'downloadedHashMatches') // use a different verifyProperty name from existing verification or it will always fail
if (ant.properties['downloadedHashMatches'] != 'true') {
ant.fail('Checksum mismatch: Downloaded archive has a different checksum than expected')
}

View file

@ -24,6 +24,7 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@ -38,13 +39,14 @@ public class ZipUtils {
* @param dir The directory to create the zip from.
* @param out The stream to write to.
*/
public static void zipDirToStream(File dir, OutputStream out, int bufferSize) throws Exception {
public static void zipDirToStream(File dir, OutputStream out, int bufferSize, Collection<File> excludedFiles) throws Exception {
// Get all files in directory and subdirectories.
ArrayList<String> fileList = new ArrayList<>();
getFilesRecursive(dir, fileList);
List<File> fileList = new ArrayList<>();
getFilesRecursive(dir, fileList, excludedFiles);
try (ZipOutputStream zos = new ZipOutputStream(out)) {
for (String filePath : fileList) {
for (File file : fileList) {
String filePath = file.getAbsolutePath();
log.info("Compressing: " + filePath);
// Creates a zip entry.
@ -73,14 +75,15 @@ public class ZipUtils {
/**
* Get files list from the directory recursive to the subdirectory.
*/
public static void getFilesRecursive(File directory, List<String> fileList) {
public static void getFilesRecursive(File directory, List<File> fileList, Collection<File> excludedFiles) {
File[] files = directory.listFiles();
if (files != null && files.length > 0) {
for (File file : files) {
if (excludedFiles != null && excludedFiles.contains(file)) continue;
if (file.isFile()) {
fileList.add(file.getAbsolutePath());
fileList.add(file);
} else {
getFilesRecursive(file, fileList);
getFilesRecursive(file, fileList, excludedFiles);
}
}
}

View file

@ -27,11 +27,13 @@ import haveno.common.crypto.KeyStorage;
import haveno.common.file.FileUtil;
import haveno.common.persistence.PersistenceManager;
import haveno.common.util.ZipUtils;
import haveno.core.xmr.wallet.XmrWalletService;
import java.io.File;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import lombok.Getter;
@ -139,6 +141,7 @@ public class CoreAccountService {
}
}
// TODO: share common code with BackupView to backup
public void backupAccount(int bufferSize, Consumer<InputStream> consume, Consumer<Exception> error) {
if (!accountExists()) throw new IllegalStateException("Cannot backup non existing account");
@ -149,9 +152,16 @@ public class CoreAccountService {
PipedInputStream in = new PipedInputStream(bufferSize); // pipe the serialized account object to stream which will be read by the consumer
PipedOutputStream out = new PipedOutputStream(in);
log.info("Zipping directory " + dataDir);
// exclude monero binaries from backup so they're reinstalled with permissions
List<File> excludedFiles = Arrays.asList(
new File(XmrWalletService.MONERO_WALLET_RPC_PATH),
new File(XmrLocalNode.MONEROD_PATH)
);
new Thread(() -> {
try {
ZipUtils.zipDirToStream(dataDir, out, bufferSize);
ZipUtils.zipDirToStream(dataDir, out, bufferSize, excludedFiles);
} catch (Exception ex) {
error.accept(ex);
}

View file

@ -530,7 +530,7 @@ public final class XmrConnectionService {
}
private void onConnectionChanged(MoneroRpcConnection currentConnection) {
if (isShutDownStarted) return;
if (isShutDownStarted || !accountService.isAccountOpen()) return;
if (currentConnection == null) {
log.warn("Setting daemon connection to null");
Thread.dumpStack();

View file

@ -113,7 +113,7 @@ public class XmrWalletService {
// monero configuration
public static final int NUM_BLOCKS_UNLOCK = 10;
public static final String MONERO_BINS_DIR = Config.baseCurrencyNetwork().isTestnet() ? System.getProperty("user.dir") + File.separator + ".localnet" : Config.appDataDir().getAbsolutePath(); // .localnet contains monero binaries and wallet files
public static final String MONERO_BINS_DIR = Config.appDataDir().getAbsolutePath();
public static final String MONERO_WALLET_RPC_NAME = Utilities.isWindows() ? "monero-wallet-rpc.exe" : "monero-wallet-rpc";
public static final String MONERO_WALLET_RPC_PATH = MONERO_BINS_DIR + File.separator + MONERO_WALLET_RPC_NAME;
public static final double MINER_FEE_TOLERANCE = 0.25; // miner fee must be within percent of estimated fee