mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
Use canonical path to the wallet destination file. Resolves issue 265.
This commit is contained in:
parent
12a652bd1e
commit
972c19a95f
@ -444,4 +444,8 @@ public class Utils {
|
||||
}
|
||||
return decode;
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
|
||||
}
|
||||
}
|
||||
|
@ -253,11 +253,13 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
stream.getFD().sync();
|
||||
stream.close();
|
||||
stream = null;
|
||||
if (!temp.renameTo(destFile)) {
|
||||
if (Utils.isWindows()) {
|
||||
// Work around an issue on Windows whereby you can't rename over existing files.
|
||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
||||
if (destFile.delete() && temp.renameTo(destFile)) return; // else fall through.
|
||||
}
|
||||
File canonical = destFile.getCanonicalFile();
|
||||
if (canonical.delete() && temp.renameTo(canonical))
|
||||
return; // else fall through.
|
||||
throw new IOException("Failed to rename " + temp + " to " + canonical);
|
||||
} else if (!temp.renameTo(destFile)) {
|
||||
throw new IOException("Failed to rename " + temp + " to " + destFile);
|
||||
}
|
||||
if (destFile.equals(autosaveToFile)) {
|
||||
|
Loading…
Reference in New Issue
Block a user