diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2021-01-05 02:11:48 -0500 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2021-01-05 02:11:48 -0500 |
commit | 5aaaad5cc1c97f1977809947dc8c427344779fe6 (patch) | |
tree | 351e6b19867d83fed3a1e6b31d508e5258f01ec4 | |
parent | 74d5a1c1724f968eeaa00afc0b25c0717cb32018 (diff) | |
parent | 877ce01d29ceaea7acbafd71812afc311550668b (diff) | |
download | jgit-5aaaad5cc1c97f1977809947dc8c427344779fe6.tar.gz jgit-5aaaad5cc1c97f1977809947dc8c427344779fe6.zip |
Merge "FileSnapshot: don't try to read file attributes twice"
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java | 21 |
1 files changed, 17 insertions, 4 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..7b4406a4b9 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 @@ -12,8 +12,10 @@ package org.eclipse.jgit.internal.storage.file; import static org.eclipse.jgit.util.FS.FileStoreAttributes.FALLBACK_FILESTORE_ATTRIBUTES; import static org.eclipse.jgit.util.FS.FileStoreAttributes.FALLBACK_TIMESTAMP_RESOLUTION; + import java.io.File; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.nio.file.attribute.BasicFileAttributes; import java.time.Duration; import java.time.Instant; @@ -226,9 +228,15 @@ public class FileSnapshot { BasicFileAttributes fileAttributes = null; try { fileAttributes = FS.DETECTED.fileAttributes(file); + } catch (NoSuchFileException e) { + this.lastModified = Instant.EPOCH; + this.size = 0L; + this.fileKey = MISSING_FILEKEY; + return; } catch (IOException e) { - this.lastModified = Instant.ofEpochMilli(file.lastModified()); - this.size = file.length(); + LOG.error(e.getMessage(), e); + this.lastModified = Instant.EPOCH; + this.size = 0L; this.fileKey = MISSING_FILEKEY; return; } @@ -309,9 +317,14 @@ public class FileSnapshot { currLastModified = fileAttributes.lastModifiedTime().toInstant(); currSize = fileAttributes.size(); currFileKey = getFileKey(fileAttributes); + } catch (NoSuchFileException e) { + currLastModified = Instant.EPOCH; + currSize = 0L; + currFileKey = MISSING_FILEKEY; } catch (IOException e) { - currLastModified = Instant.ofEpochMilli(path.lastModified()); - currSize = path.length(); + LOG.error(e.getMessage(), e); + currLastModified = Instant.EPOCH; + currSize = 0L; currFileKey = MISSING_FILEKEY; } sizeChanged = isSizeChanged(currSize); |