Prevent file system access for WatchService DELETE events in FolderObserver (#4907)

Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
This commit is contained in:
Nadahar
2025-07-17 12:10:13 +02:00
committed by GitHub
parent 2ae969431c
commit a6ea26f8f5
@@ -255,7 +255,19 @@ public class FolderObserver implements WatchService.WatchEventListener {
}
private void checkPath(final Path path, final WatchService.Kind kind) {
String fileName = path.getFileName().toString();
try {
// Checking isHidden() on a deleted file will throw an IOException on some file systems,
// so deal with deletion first.
if (kind == DELETE) {
synchronized (FolderObserver.class) {
modelRepository.removeModel(fileName);
namePathMap.remove(fileName);
logger.debug("Removed '{}' model ", fileName);
}
return;
}
if (Files.isHidden(path)) {
// we omit parsing of hidden files possibly created by editors or operating systems
if (logger.isDebugEnabled()) {
@@ -265,7 +277,6 @@ public class FolderObserver implements WatchService.WatchEventListener {
}
synchronized (FolderObserver.class) {
String fileName = path.getFileName().toString();
if (kind == CREATE || kind == MODIFY) {
String extension = getExtension(fileName);
if (parsers.contains(extension)) {
@@ -286,10 +297,6 @@ public class FolderObserver implements WatchService.WatchEventListener {
path.toAbsolutePath());
}
}
} else if (kind == WatchService.Kind.DELETE) {
modelRepository.removeModel(fileName);
namePathMap.remove(fileName);
logger.debug("Removed '{}' model ", fileName);
}
}
} catch (Exception e) {