revert change to restore wallet cache (wip)

This commit is contained in:
woodser 2024-10-01 10:00:01 -04:00
parent ea3f099df7
commit e30f684c93

View file

@ -1478,45 +1478,46 @@ public class XmrWalletService extends XmrWalletBase {
walletFull = MoneroWalletFull.openWallet(config); walletFull = MoneroWalletFull.openWallet(config);
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to open full wallet '{}', attempting to use backup cache, error={}", config.getPath(), e.getMessage()); log.warn("Failed to open full wallet '{}', attempting to use backup cache, error={}", config.getPath(), e.getMessage());
boolean retrySuccessful = false; throw e;
try { // boolean retrySuccessful = false;
// try {
// rename wallet cache to backup // // rename wallet cache to backup
String cachePath = walletDir.toString() + File.separator + MONERO_WALLET_NAME; // String cachePath = walletDir.toString() + File.separator + MONERO_WALLET_NAME;
File originalCacheFile = new File(cachePath); // File originalCacheFile = new File(cachePath);
if (originalCacheFile.exists()) originalCacheFile.renameTo(new File(cachePath + ".backup")); // if (originalCacheFile.exists()) originalCacheFile.renameTo(new File(cachePath + ".backup"));
// copy latest wallet cache backup to main folder // // copy latest wallet cache backup to main folder
File backupCacheFile = FileUtil.getLatestBackupFile(walletDir, MONERO_WALLET_NAME); // File backupCacheFile = FileUtil.getLatestBackupFile(walletDir, MONERO_WALLET_NAME);
if (backupCacheFile != null) FileUtil.copyFile(backupCacheFile, new File(cachePath)); // if (backupCacheFile != null) FileUtil.copyFile(backupCacheFile, new File(cachePath));
// retry opening wallet without original cache // // retry opening wallet without original cache
try { // try {
walletFull = MoneroWalletFull.openWallet(config); // walletFull = MoneroWalletFull.openWallet(config);
log.info("Successfully opened full wallet using backup cache"); // log.info("Successfully opened full wallet using backup cache");
retrySuccessful = true; // retrySuccessful = true;
} catch (Exception e2) { // } catch (Exception e2) {
// ignore // // ignore
} // }
// handle success or failure // // handle success or failure
File originalCacheBackup = new File(cachePath + ".backup"); // File originalCacheBackup = new File(cachePath + ".backup");
if (retrySuccessful) { // if (retrySuccessful) {
if (originalCacheBackup.exists()) originalCacheBackup.delete(); // delete original wallet cache backup // if (originalCacheBackup.exists()) originalCacheBackup.delete(); // delete original wallet cache backup
} else { // } else {
// restore original wallet cache // // restore original wallet cache
log.warn("Failed to open full wallet using backup cache, restoring original cache"); // log.warn("Failed to open full wallet using backup cache, restoring original cache");
File cacheFile = new File(cachePath); // File cacheFile = new File(cachePath);
if (cacheFile.exists()) cacheFile.delete(); // if (cacheFile.exists()) cacheFile.delete();
if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath)); // if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath));
// throw exception // // throw exception
throw e; // throw e;
} // }
} catch (Exception e2) { // } catch (Exception e2) {
throw e; // throw original exception // throw e; // throw original exception
} // }
} }
if (walletFull.getDaemonConnection() != null) walletFull.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE); if (walletFull.getDaemonConnection() != null) walletFull.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE);
log.info("Done opening full wallet " + config.getPath()); log.info("Done opening full wallet " + config.getPath());
@ -1583,45 +1584,46 @@ public class XmrWalletService extends XmrWalletBase {
walletRpc.openWallet(config); walletRpc.openWallet(config);
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to open RPC wallet '{}', attempting to use backup cache, error={}", config.getPath(), e.getMessage()); log.warn("Failed to open RPC wallet '{}', attempting to use backup cache, error={}", config.getPath(), e.getMessage());
boolean retrySuccessful = false; throw e;
try { // boolean retrySuccessful = false;
// try {
// rename wallet cache to backup // // rename wallet cache to backup
String cachePath = walletDir.toString() + File.separator + MONERO_WALLET_NAME; // String cachePath = walletDir.toString() + File.separator + MONERO_WALLET_NAME;
File originalCacheFile = new File(cachePath); // File originalCacheFile = new File(cachePath);
if (originalCacheFile.exists()) originalCacheFile.renameTo(new File(cachePath + ".backup")); // if (originalCacheFile.exists()) originalCacheFile.renameTo(new File(cachePath + ".backup"));
// copy latest wallet cache backup to main folder // // copy latest wallet cache backup to main folder
File backupCacheFile = FileUtil.getLatestBackupFile(walletDir, MONERO_WALLET_NAME); // File backupCacheFile = FileUtil.getLatestBackupFile(walletDir, MONERO_WALLET_NAME);
if (backupCacheFile != null) FileUtil.copyFile(backupCacheFile, new File(cachePath)); // if (backupCacheFile != null) FileUtil.copyFile(backupCacheFile, new File(cachePath));
// retry opening wallet without original cache // // retry opening wallet without original cache
try { // try {
walletRpc.openWallet(config); // walletRpc.openWallet(config);
log.info("Successfully opened RPC wallet using backup cache"); // log.info("Successfully opened RPC wallet using backup cache");
retrySuccessful = true; // retrySuccessful = true;
} catch (Exception e2) { // } catch (Exception e2) {
// ignore // // ignore
} // }
// handle success or failure // // handle success or failure
File originalCacheBackup = new File(cachePath + ".backup"); // File originalCacheBackup = new File(cachePath + ".backup");
if (retrySuccessful) { // if (retrySuccessful) {
if (originalCacheBackup.exists()) originalCacheBackup.delete(); // delete original wallet cache backup // if (originalCacheBackup.exists()) originalCacheBackup.delete(); // delete original wallet cache backup
} else { // } else {
// restore original wallet cache // // restore original wallet cache
log.warn("Failed to open RPC wallet using backup cache, restoring original cache"); // log.warn("Failed to open RPC wallet using backup cache, restoring original cache");
File cacheFile = new File(cachePath); // File cacheFile = new File(cachePath);
if (cacheFile.exists()) cacheFile.delete(); // if (cacheFile.exists()) cacheFile.delete();
if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath)); // if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath));
// throw exception // // throw exception
throw e; // throw e;
} // }
} catch (Exception e2) { // } catch (Exception e2) {
throw e; // throw original exception // throw e; // throw original exception
} // }
} }
if (walletRpc.getDaemonConnection() != null) walletRpc.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE); if (walletRpc.getDaemonConnection() != null) walletRpc.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE);
log.info("Done opening RPC wallet " + config.getPath()); log.info("Done opening RPC wallet " + config.getPath());