Browse Source

Merge "LockFile.commit: retry renaming"

tags/v0.10.1
Shawn Pearce 13 years ago
parent
commit
6462be8350
1 changed files with 20 additions and 1 deletions
  1. 20
    1
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java

+ 20
- 1
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java View File

@@ -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();

Loading…
Cancel
Save