FileWatchingService should not throw for missing file (#126264)

Missing file is a valid state for FileWatchingService so that the
exception should be suppressed.
This commit is contained in:
Yang Wang 2025-04-08 09:56:35 +10:00 committed by GitHub
parent 991e80d56e
commit 997a7b8fab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -0,0 +1,5 @@
pr: 126264
summary: '`FileWatchingService` shoudld not throw for missing file'
area: Infra/Settings
type: enhancement
issues: []

View file

@ -116,15 +116,13 @@ public abstract class AbstractFileWatchingService extends AbstractLifecycleCompo
}
private FileUpdateState readFileUpdateState(Path path) throws IOException {
BasicFileAttributes attr;
try {
attr = filesReadAttributes(path, BasicFileAttributes.class);
BasicFileAttributes attr = filesReadAttributes(path, BasicFileAttributes.class);
return new FileUpdateState(attr.lastModifiedTime().toMillis(), path.toRealPath().toString(), attr.fileKey());
} catch (NoSuchFileException e) {
// file doesn't exist anymore
return null;
}
return new FileUpdateState(attr.lastModifiedTime().toMillis(), path.toRealPath().toString(), attr.fileKey());
}
// platform independent way to tell if a file changed