Skip to content

Commit 684868a

Browse files
author
Ravi Nadahar
committed
Prevent file system access for WatchService DELETE events in FolderObserver
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
1 parent 2ae9694 commit 684868a

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

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

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
@@ -255,7 +255,19 @@ public boolean accept(Path entry) throws IOException {
255255
}
256256

257257
private void checkPath(final Path path, final WatchService.Kind kind) {
258+
String fileName = path.getFileName().toString();
258259
try {
260+
// Checking isHidden() on a deleted file will throw an IOException on some file systems,
261+
// so deal with deletion first.
262+
if (kind == DELETE) {
263+
synchronized (FolderObserver.class) {
264+
modelRepository.removeModel(fileName);
265+
namePathMap.remove(fileName);
266+
logger.debug("Removed '{}' model ", fileName);
267+
}
268+
return;
269+
}
270+
259271
if (Files.isHidden(path)) {
260272
// we omit parsing of hidden files possibly created by editors or operating systems
261273
if (logger.isDebugEnabled()) {
@@ -265,7 +277,6 @@ private void checkPath(final Path path, final WatchService.Kind kind) {
265277
}
266278

267279
synchronized (FolderObserver.class) {
268-
String fileName = path.getFileName().toString();
269280
if (kind == CREATE || kind == MODIFY) {
270281
String extension = getExtension(fileName);
271282
if (parsers.contains(extension)) {
@@ -286,10 +297,6 @@ private void checkPath(final Path path, final WatchService.Kind kind) {
286297
path.toAbsolutePath());
287298
}
288299
}
289-
} else if (kind == WatchService.Kind.DELETE) {
290-
modelRepository.removeModel(fileName);
291-
namePathMap.remove(fileName);
292-
logger.debug("Removed '{}' model ", fileName);
293300
}
294301
}
295302
} catch (Exception e) {

0 commit comments

Comments
 (0)