File.renameTo behaves differently on Unix and Windows

On Windows renameTo will not overwrite a file, so it must be deleted
first. The fix for Bug 402834 did not account for that.

Bug: 403685
Change-Id: I3453342c17e064dcb50906a540172978941a10a6
This commit is contained in:
Robin Rosenberg 2013-03-19 14:19:28 +01:00 committed by Christian Halstrick
parent d0e92885e9
commit edf0da9c6e
1 changed files with 6 additions and 10 deletions

View File

@ -1126,16 +1126,12 @@ public static void checkoutEntry(final Repository repo, File f,
fs.setExecute(tmpFile, false); fs.setExecute(tmpFile, false);
} }
} }
if (!tmpFile.renameTo(f)) { try {
// tried to rename which failed. Let' delete the target file and try FileUtils.rename(tmpFile, f);
// again } catch (IOException e) {
FileUtils.delete(f, FileUtils.EMPTY_DIRECTORIES_ONLY throw new IOException(MessageFormat.format(
| FileUtils.RECURSIVE); JGitText.get().couldNotWriteFile, tmpFile.getPath(),
if (!tmpFile.renameTo(f)) { f.getPath()));
throw new IOException(MessageFormat.format(
JGitText.get().couldNotWriteFile, tmpFile.getPath(),
f.getPath()));
}
} }
entry.setLastModified(f.lastModified()); entry.setLastModified(f.lastModified());
if (opt.getAutoCRLF() != AutoCRLF.FALSE) if (opt.getAutoCRLF() != AutoCRLF.FALSE)