3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 14:54:15 +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()) {
// 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.");
}
}
}