diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2021-12-04 19:14:56 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2021-12-04 19:19:16 +0100 |
commit | 70b894da19caf1429c00375f8f730725d8958f13 (patch) | |
tree | ca8bb0dfb8a3a5b6e5910094f633b81b18db5e07 /org.eclipse.jgit | |
parent | 122237439daee43956fe9f4255365afd40823e21 (diff) | |
parent | 73b3cbd26b4f2e46972d0cbc3efab4f14a8033e2 (diff) | |
download | jgit-70b894da19caf1429c00375f8f730725d8958f13.tar.gz jgit-70b894da19caf1429c00375f8f730725d8958f13.zip |
Merge branch 'stable-5.8' into stable-5.9
* stable-5.8:
Add missing @since tags
Add missing @since tag
Add missing @since tags
Remove unused import in ApacheSshTest
Update maven plugins
Ignore missing javadoc in test bundles
storage: file: De-duplicate File.exists()+File.isFile()
RefDirectory.scanRef: Re-use file existence check done in snapshot creation
FileSnapshot: Lazy load file store attributes cache
Update eclipse-jarsigner-plugin to 1.3.2
Fix p2 repository URLs
Change-Id: I5e7c204c0e4c428df6f3b27ba1fc06326983f27c
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 35 insertions, 9 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 54ff7d29c6..d7f6ef316d 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 @@ -185,6 +185,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 */ @@ -220,9 +226,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); @@ -366,7 +370,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); @@ -403,6 +407,15 @@ public class FileSnapshot { return equals(other); } + /** + * Check if the file exists + * + * @return true if the file exists + */ + public boolean fileExists() { + return !MISSING_FILEKEY.equals(this.fileKey); + } + /** {@inheritDoc} */ @Override public int hashCode() { @@ -487,10 +500,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; @@ -550,4 +563,13 @@ public class FileSnapshot { } return changed; } + + private FileStoreAttributes fileStoreAttributeCache() { + if (fileStoreAttributeCache == null) { + fileStoreAttributeCache = useConfig + ? FS.getFileStoreAttributes(file.toPath().getParent()) + : FALLBACK_FILESTORE_ATTRIBUTES; + } + return fileStoreAttributeCache; + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java index e27518690b..7179d140b4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java @@ -151,7 +151,7 @@ public class ObjectDirectoryPackParser extends PackParser { String p = pack.getAbsolutePath(); String i = p.substring(0, p.length() - ".pack".length()) + ".idx"; //$NON-NLS-1$ //$NON-NLS-2$ File idx = new File(i); - if (idx.exists() && idx.isFile()) + if (idx.isFile()) size += idx.length(); return size; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 17a910008c..2167262dd5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -1092,10 +1092,14 @@ public class RefDirectory extends RefDatabase { final int limit = 4096; final byte[] buf; FileSnapshot otherSnapshot = FileSnapshot.save(path); + if (!otherSnapshot.fileExists()) { + return null; + } + try { buf = IO.readSome(path, limit); } catch (FileNotFoundException noFile) { - if (path.exists() && path.isFile()) { + if (path.isFile()) { throw noFile; } return null; // doesn't exist or no file; not a reference. |