Browse Source

In LockFile#waitForStatChange wait in units of file time resolution

Since we now measure file time resolution we can use it to replace the
hard coded wait time of 25ms. FileSnapshot#equals will return true until
the mtime of the old (o) and the new FileSnapshot (n) differ by at least
one  file time resolution.

Change-Id: Icb713a80ce9eb929242ed083406bfb6650c72223
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.1
Matthias Sohn 5 years ago
parent
commit
3b368d5578
  1. 5
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java

5
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java

@ -61,6 +61,7 @@ import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime;
import java.text.MessageFormat;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
@ -425,8 +426,10 @@ public class LockFile {
public void waitForStatChange() throws InterruptedException {
FileSnapshot o = FileSnapshot.save(ref);
FileSnapshot n = FileSnapshot.save(lck);
long fsTimeResolution = FS.getFileStoreAttributes(lck.toPath())
.getFsTimestampResolution().toNanos();
while (o.equals(n)) {
Thread.sleep(25 /* milliseconds */);
TimeUnit.NANOSECONDS.sleep(fsTimeResolution);
try {
Files.setLastModifiedTime(lck.toPath(),
FileTime.from(Instant.now()));

Loading…
Cancel
Save