3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

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.

This commit is contained in:
Mike Hearn 2014-05-05 14:42:52 +02:00
parent fbbdbb576e
commit 0e74eba29f

View File

@ -312,7 +312,8 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
if (Utils.isWindows()) { if (Utils.isWindows()) {
// Work around an issue on Windows whereby you can't rename over existing files. // Work around an issue on Windows whereby you can't rename over existing files.
File canonical = destFile.getCanonicalFile(); 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)) if (temp.renameTo(canonical))
return; // else fall through. return; // else fall through.
throw new IOException("Failed to rename " + temp + " to " + canonical); throw new IOException("Failed to rename " + temp + " to " + canonical);
@ -327,8 +328,8 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
if (stream != null) { if (stream != null) {
stream.close(); stream.close();
} }
if (temp.delete()) { if (temp.exists()) {
log.warn("Deleted temp file after failed save."); log.warn("Temp file still exists after failed save.");
} }
} }
} }