summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java27
1 files changed, 20 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
index 976f946e5d..487ae06014 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
@@ -218,6 +218,12 @@ public class FileSnapshot {
private FileStoreAttributes fileStoreAttributeCache;
/**
+ * if {@code true} read filesystem time resolution from configuration file
+ * otherwise use fallback resolution
+ */
+ private boolean useConfig;
+
+ /**
* Object that uniquely identifies the given file, or {@code
* null} if a file key is not available
*/
@@ -253,9 +259,7 @@ public class FileSnapshot {
protected FileSnapshot(File file, boolean useConfig) {
this.file = file;
this.lastRead = Instant.now();
- this.fileStoreAttributeCache = useConfig
- ? FS.getFileStoreAttributes(file.toPath().getParent())
- : FALLBACK_FILESTORE_ATTRIBUTES;
+ this.useConfig = useConfig;
BasicFileAttributes fileAttributes = null;
try {
fileAttributes = FS.DETECTED.fileAttributes(file);
@@ -399,7 +403,7 @@ public class FileSnapshot {
* if sleep was interrupted
*/
public void waitUntilNotRacy() throws InterruptedException {
- long timestampResolution = fileStoreAttributeCache
+ long timestampResolution = fileStoreAttributeCache()
.getFsTimestampResolution().toNanos();
while (isRacyClean(Instant.now())) {
TimeUnit.NANOSECONDS.sleep(timestampResolution);
@@ -519,10 +523,10 @@ public class FileSnapshot {
}
private long getEffectiveRacyThreshold() {
- long timestampResolution = fileStoreAttributeCache
+ long timestampResolution = fileStoreAttributeCache()
.getFsTimestampResolution().toNanos();
- long minRacyInterval = fileStoreAttributeCache.getMinimalRacyInterval()
- .toNanos();
+ long minRacyInterval = fileStoreAttributeCache()
+ .getMinimalRacyInterval().toNanos();
long max = Math.max(timestampResolution, minRacyInterval);
// safety margin: factor 2.5 below 100ms otherwise 1.25
return max < 100_000_000L ? max * 5 / 2 : max * 5 / 4;
@@ -582,4 +586,13 @@ public class FileSnapshot {
}
return changed;
}
+
+ private FileStoreAttributes fileStoreAttributeCache() {
+ if (fileStoreAttributeCache == null) {
+ fileStoreAttributeCache = useConfig
+ ? FS.getFileStoreAttributes(file.toPath().getParent())
+ : FALLBACK_FILESTORE_ATTRIBUTES;
+ }
+ return fileStoreAttributeCache;
+ }
}