Skip to content

Commit 997a7b8

Browse files
authored
FileWatchingService should not throw for missing file (#126264)
Missing file is a valid state for FileWatchingService so that the exception should be suppressed.
1 parent 991e80d commit 997a7b8

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docs/changelog/126264.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 126264
2+
summary: '`FileWatchingService` shoudld not throw for missing file'
3+
area: Infra/Settings
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/common/file/AbstractFileWatchingService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,13 @@ public final boolean watching() {
116116
}
117117

118118
private FileUpdateState readFileUpdateState(Path path) throws IOException {
119-
BasicFileAttributes attr;
120119
try {
121-
attr = filesReadAttributes(path, BasicFileAttributes.class);
120+
BasicFileAttributes attr = filesReadAttributes(path, BasicFileAttributes.class);
121+
return new FileUpdateState(attr.lastModifiedTime().toMillis(), path.toRealPath().toString(), attr.fileKey());
122122
} catch (NoSuchFileException e) {
123123
// file doesn't exist anymore
124124
return null;
125125
}
126-
127-
return new FileUpdateState(attr.lastModifiedTime().toMillis(), path.toRealPath().toString(), attr.fileKey());
128126
}
129127

130128
// platform independent way to tell if a file changed

0 commit comments

Comments
 (0)