From 0e74eba29f6d09a16912e8a84131716081809f5c Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 5 May 2014 14:42:52 +0200 Subject: [PATCH] WalletFiles: don't delete temp file if rename failed. It might be the only copy of the wallet we have! Only really should affect Windows. --- core/src/main/java/com/google/bitcoin/core/Wallet.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index 2de64bbe..7b07fd9e 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -312,7 +312,8 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi if (Utils.isWindows()) { // Work around an issue on Windows whereby you can't rename over existing files. File canonical = destFile.getCanonicalFile(); - canonical.delete(); + if (!canonical.delete()) + throw new IOException("Failed to delete canonical wallet file for replacement with autosave"); if (temp.renameTo(canonical)) return; // else fall through. throw new IOException("Failed to rename " + temp + " to " + canonical); @@ -327,8 +328,8 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi if (stream != null) { stream.close(); } - if (temp.delete()) { - log.warn("Deleted temp file after failed save."); + if (temp.exists()) { + log.warn("Temp file still exists after failed save."); } } }