]> source.dussan.org Git - jgit.git/commitdiff
File.renameTo behaves differently on Unix and Windows 21/11321/4
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 19 Mar 2013 13:19:28 +0000 (14:19 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Mon, 25 Mar 2013 23:48:44 +0000 (00:48 +0100)
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

org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

index dd9023fc7743f0b6940880a43618d1db74b5181a..6fb56ed1b79f4c785307f3c3309df748dd2ad222 100644 (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)