Merge "File.renameTo behaves differently on Unix and Windows"

This commit is contained in:
Matthias Sohn 2013-03-27 09:09:04 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit edd47d10b9
1 changed files with 6 additions and 10 deletions

View File

@ -1126,17 +1126,13 @@ 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
| FileUtils.RECURSIVE);
if (!tmpFile.renameTo(f)) {
throw new IOException(MessageFormat.format( throw new IOException(MessageFormat.format(
JGitText.get().couldNotWriteFile, tmpFile.getPath(), JGitText.get().couldNotWriteFile, tmpFile.getPath(),
f.getPath())); f.getPath()));
} }
}
entry.setLastModified(f.lastModified()); entry.setLastModified(f.lastModified());
if (opt.getAutoCRLF() != AutoCRLF.FALSE) if (opt.getAutoCRLF() != AutoCRLF.FALSE)
entry.setLength(f.length()); // AutoCRLF wants on-disk-size entry.setLength(f.length()); // AutoCRLF wants on-disk-size