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
stable-3.0
Robin Rosenberg 12 years ago committed by Christian Halstrick
parent
commit
edf0da9c6e
  1. 10
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

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

@ -1126,17 +1126,13 @@ public class DirCacheCheckout {
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

Loading…
Cancel
Save