aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fick <mfick@nvidia.com>2024-12-05 13:37:37 -0800
committerMartin Fick <mfick@nvidia.com>2024-12-05 14:59:46 -0800
commitdd8b13acc0d60b53f399ce7e0c6718b81ad2ab16 (patch)
tree1c74e2d233ebe9b8666a933693ffd7ee0641fa05
parent44d61a3d727eb68db9e57acec0704bfc6758f878 (diff)
downloadjgit-dd8b13acc0d60b53f399ce7e0c6718b81ad2ab16.tar.gz
jgit-dd8b13acc0d60b53f399ce7e0c6718b81ad2ab16.zip
FileSnapshot: refactor to share error handling
It is important to keep the exception handling for getting file attributes the same in all places in this class; put that code into a common method. Change-Id: I1fcce5efd10aa562a4e0e34d3ce94bcc83850237 Signed-off-by: Martin Fick <mfick@nvidia.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java30
1 files changed, 15 insertions, 15 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 c88ac984ec..c5e9e99673 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
@@ -22,6 +22,7 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
+import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -231,14 +232,8 @@ public class FileSnapshot {
this.useConfig = useConfig;
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) {
- LOG.error(e.getMessage(), e);
+ fileAttributes = getFileAttributes(file);
+ } catch (NoSuchElementException e) {
this.lastModified = Instant.EPOCH;
this.size = 0L;
this.fileKey = MISSING_FILEKEY;
@@ -319,16 +314,11 @@ public class FileSnapshot {
long currSize;
Object currFileKey;
try {
- BasicFileAttributes fileAttributes = FS.DETECTED.fileAttributes(path);
+ BasicFileAttributes fileAttributes = getFileAttributes(path);
currLastModified = fileAttributes.lastModifiedTime().toInstant();
currSize = fileAttributes.size();
currFileKey = getFileKey(fileAttributes);
- } catch (NoSuchFileException e) {
- currLastModified = Instant.EPOCH;
- currSize = 0L;
- currFileKey = MISSING_FILEKEY;
- } catch (IOException e) {
- LOG.error(e.getMessage(), e);
+ } catch (NoSuchElementException e) {
currLastModified = Instant.EPOCH;
currSize = 0L;
currFileKey = MISSING_FILEKEY;
@@ -586,4 +576,14 @@ public class FileSnapshot {
}
return fileStoreAttributeCache;
}
+
+ private static BasicFileAttributes getFileAttributes(File path) throws NoSuchElementException {
+ try {
+ return FS.DETECTED.fileAttributes(path);
+ } catch (NoSuchFileException e) {
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ }
+ throw new NoSuchElementException(path.toString());
+ }
}