From: J-N-K Date: Wed, 26 Apr 2023 19:52:00 +0000 (+0200) Subject: Fix exec transformation service whitelisting (#14884) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=dba7fcc69765196dc04472ea3d9f8b36d707516e;p=openhab-addons.git Fix exec transformation service whitelisting (#14884) Reported on the german openHAB forum. Signed-off-by: Jan N. Klug --- diff --git a/bundles/org.openhab.transform.exec/src/main/java/org/openhab/transform/exec/internal/ExecTransformationWhitelistWatchService.java b/bundles/org.openhab.transform.exec/src/main/java/org/openhab/transform/exec/internal/ExecTransformationWhitelistWatchService.java index 5b18820f26..590a71b48a 100644 --- a/bundles/org.openhab.transform.exec/src/main/java/org/openhab/transform/exec/internal/ExecTransformationWhitelistWatchService.java +++ b/bundles/org.openhab.transform.exec/src/main/java/org/openhab/transform/exec/internal/ExecTransformationWhitelistWatchService.java @@ -41,12 +41,14 @@ public class ExecTransformationWhitelistWatchService implements WatchService.Wat private final Logger logger = LoggerFactory.getLogger(ExecTransformationWhitelistWatchService.class); private final Set commandWhitelist = new HashSet<>(); private final WatchService watchService; + private final Path watchFile; @Activate public ExecTransformationWhitelistWatchService( final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) { this.watchService = watchService; - watchService.registerListener(this, COMMAND_WHITELIST_FILE); + this.watchFile = watchService.getWatchPath().resolve(COMMAND_WHITELIST_FILE); + watchService.registerListener(this, COMMAND_WHITELIST_FILE, false); // read initial content processWatchEvent(WatchService.Kind.CREATE, COMMAND_WHITELIST_FILE); @@ -59,9 +61,9 @@ public class ExecTransformationWhitelistWatchService implements WatchService.Wat @Override public void processWatchEvent(WatchService.Kind kind, Path path) { - if (path.endsWith(COMMAND_WHITELIST_FILE)) { - commandWhitelist.clear(); - try (Stream lines = Files.lines(path)) { + commandWhitelist.clear(); + if (kind != WatchService.Kind.DELETE) { + try (Stream lines = Files.lines(watchFile)) { lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add); logger.debug("Updated command whitelist: {}", commandWhitelist); } catch (IOException e) {