summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJens Baumgart2010-12-06 07:40:07 (EST)
committer Jens Baumgart2010-12-06 07:40:07 (EST)
commitcbf5ff6ac7762e2b7170edae9d1563ae3869544a (patch)
treec9cd8035e76780ec588e42614a24cbe7a95d7c15
parent90fbc1db3a8b4439474e1601f2d842e29594d381 (diff)
downloadjgit-cbf5ff6ac7762e2b7170edae9d1563ae3869544a.zip
jgit-cbf5ff6ac7762e2b7170edae9d1563ae3869544a.tar.gz
jgit-cbf5ff6ac7762e2b7170edae9d1563ae3869544a.tar.bz2
LockFile.commit: retry renamingrefs/changes/49/2049/1
Currently the following can happen in LockFile.commit: deletion of the original file succeeds but renaming fails afterwards. In this case the original file (e.g. branch file in refs/heads) is lost. To workaround the issue the same retry logic as for file deletion is applied to file renaming. Bug: 331890 Change-Id: I68620c07f2d3ab7f3279c71a91e184e8eac69832 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Philipp Thun <philipp.thun@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
index 6199f4c..c1fb704 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
@@ -397,7 +397,7 @@ public class LockFile {
if (lck.renameTo(ref))
return true;
if (!ref.exists() || deleteRef())
- if (lck.renameTo(ref))
+ if (renameLock())
return true;
unlock();
return false;
@@ -422,6 +422,25 @@ public class LockFile {
return false;
}
+ private boolean renameLock() {
+ if (!fs.retryFailedLockFileCommit())
+ return lck.renameTo(ref);
+
+ // File renaming fails on windows if another thread is
+ // concurrently reading the same file. So try a few times.
+ //
+ for (int attempts = 0; attempts < 10; attempts++) {
+ if (lck.renameTo(ref))
+ return true;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ return false;
+ }
+ }
+ return false;
+ }
+
private void saveStatInformation() {
if (needStatInformation)
commitLastModified = lck.lastModified();