summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2013-03-19 14:19:28 +0100
committerChristian Halstrick <christian.halstrick@sap.com>2013-03-26 00:48:44 +0100
commitedf0da9c6ee06dbf702b0b16aa75539a11b74814 (patch)
tree5dad4fd37c62248123082e69c3cf251018f52d52
parentd0e92885e911c96be917574a5f804bf64d622cf9 (diff)
downloadjgit-edf0da9c6ee06dbf702b0b16aa75539a11b74814.tar.gz
jgit-edf0da9c6ee06dbf702b0b16aa75539a11b74814.zip
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
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java16
1 files changed, 6 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
index dd9023fc77..6fb56ed1b7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
@@ -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)