Skip to content

Commit 0128b2b

Browse files
author
Ravi Nadahar
committed
Prevent file system access for WatchService DELETE events in FolderObserver
Signed-off-by: Ravi Nadahar <[email protected]>
1 parent 67303fa commit 0128b2b

File tree

1 file changed

+12
-5
lines changed
  • bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/folder

1 file changed

+12
-5
lines changed

bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/folder/FolderObserver.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,19 @@ public boolean accept(Path entry) throws IOException {
236236
}
237237

238238
private void checkPath(final Path path, final WatchService.Kind kind) {
239+
String fileName = path.getFileName().toString();
239240
try {
241+
// Checking isHidden() on a deleted file will throw an IOException on some file systems,
242+
// so deal with deletion first.
243+
if (kind == DELETE) {
244+
synchronized (FolderObserver.class) {
245+
modelRepository.removeModel(fileName);
246+
namePathMap.remove(fileName);
247+
logger.debug("Removed '{}' model ", fileName);
248+
}
249+
return;
250+
}
251+
240252
if (Files.isHidden(path)) {
241253
// we omit parsing of hidden files possibly created by editors or operating systems
242254
if (logger.isDebugEnabled()) {
@@ -246,7 +258,6 @@ private void checkPath(final Path path, final WatchService.Kind kind) {
246258
}
247259

248260
synchronized (FolderObserver.class) {
249-
String fileName = path.getFileName().toString();
250261
if (kind == CREATE || kind == MODIFY) {
251262
String extension = getExtension(fileName);
252263
if (parsers.contains(extension)) {
@@ -267,10 +278,6 @@ private void checkPath(final Path path, final WatchService.Kind kind) {
267278
path.toAbsolutePath());
268279
}
269280
}
270-
} else if (kind == WatchService.Kind.DELETE) {
271-
modelRepository.removeModel(fileName);
272-
namePathMap.remove(fileName);
273-
logger.debug("Removed '{}' model ", fileName);
274281
}
275282
}
276283
} catch (Exception e) {

0 commit comments

Comments
 (0)