mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-25 07:07:39 +01: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:
parent
fbbdbb576e
commit
0e74eba29f
1 changed files with 4 additions and 3 deletions
|
@ -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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue