mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[exec] Fix whitelist not read (#14522)
Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
b2bf7256db
commit
44634a6e89
@ -43,11 +43,13 @@ public class ExecWhitelistWatchService implements WatchService.WatchEventListene
|
|||||||
private final Logger logger = LoggerFactory.getLogger(ExecWhitelistWatchService.class);
|
private final Logger logger = LoggerFactory.getLogger(ExecWhitelistWatchService.class);
|
||||||
private final Set<String> commandWhitelist = new HashSet<>();
|
private final Set<String> commandWhitelist = new HashSet<>();
|
||||||
private final WatchService watchService;
|
private final WatchService watchService;
|
||||||
|
private final Path watchFile;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public ExecWhitelistWatchService(
|
public ExecWhitelistWatchService(
|
||||||
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
|
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
|
||||||
this.watchService = watchService;
|
this.watchService = watchService;
|
||||||
|
this.watchFile = watchService.getWatchPath().resolve(COMMAND_WHITELIST_FILE);
|
||||||
watchService.registerListener(this, COMMAND_WHITELIST_FILE, false);
|
watchService.registerListener(this, COMMAND_WHITELIST_FILE, false);
|
||||||
|
|
||||||
// read initial content
|
// read initial content
|
||||||
@ -61,9 +63,9 @@ public class ExecWhitelistWatchService implements WatchService.WatchEventListene
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processWatchEvent(WatchService.Kind kind, Path path) {
|
public void processWatchEvent(WatchService.Kind kind, Path path) {
|
||||||
if (path.endsWith(COMMAND_WHITELIST_FILE)) {
|
|
||||||
commandWhitelist.clear();
|
commandWhitelist.clear();
|
||||||
try (Stream<String> lines = Files.lines(path)) {
|
if (kind != WatchService.Kind.DELETE) {
|
||||||
|
try (Stream<String> lines = Files.lines(watchFile)) {
|
||||||
lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add);
|
lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add);
|
||||||
logger.debug("Updated command whitelist: {}", commandWhitelist);
|
logger.debug("Updated command whitelist: {}", commandWhitelist);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user