Use canonical path to the wallet destination file. Resolves issue 265.

This commit is contained in:
Mike Hearn 2013-01-04 17:54:17 +01:00
parent 12a652bd1e
commit 972c19a95f
2 changed files with 10 additions and 4 deletions

View File

@ -444,4 +444,8 @@ public class Utils {
}
return decode;
}
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
}
}

View File

@ -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)) {