Browse Source

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
tags/v3.0.0.201305080800-m7
Robin Rosenberg 11 years ago
parent
commit
edf0da9c6e
1 changed files with 6 additions and 10 deletions
  1. 6
    10
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

+ 6
- 10
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java View File

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

Loading…
Cancel
Save