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>
This commit is contained in:
Matthias Sohn 2019-08-05 18:00:35 +02:00
parent 6857138e19
commit 3b368d5578
1 changed files with 4 additions and 1 deletions

View File

@ -61,6 +61,7 @@
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 void setFSync(boolean on) {
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()));