Skip to content

Commit

Permalink
WalletFiles: don't delete temp file if rename failed. It might be the…
Browse files Browse the repository at this point in the history
… only copy of the wallet we have! Only really should affect Windows.
  • Loading branch information
mikehearn committed May 5, 2014
1 parent fbbdbb5 commit 0e74eba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/com/google/bitcoin/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ public void saveToFile(File temp, File destFile) throws IOException {
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);
Expand All @@ -327,8 +328,8 @@ public void saveToFile(File temp, File destFile) throws IOException {
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.");
}
}
}
Expand Down

0 comments on commit 0e74eba

Please sign in to comment.