Fix ready marker not set for model when folder is missing (#4897)

Related to #3823
Replaces #4444

If the sub-folder where models are supposed to be found does not exist, the service is marked as ready anyway.
If not, start level 100 could be never reached at OH startup.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo
2025-07-13 17:16:47 +02:00
committed by GitHub
parent 20610fbd97
commit ff1156566b
@@ -120,6 +120,11 @@ public class FolderObserver implements WatchService.WatchEventListener {
@Activate
public void activate(ComponentContext ctx) {
logger.debug("FolderObserver activate");
/* set of file extensions for added parsers before activation but without an existing directory */
Set<String> parsersWithoutFolder = new HashSet<>();
Dictionary<String, Object> config = ctx.getProperties();
Enumeration<String> keys = config.keys();
@@ -132,10 +137,11 @@ public class FolderObserver implements WatchService.WatchEventListener {
}
Path folderPath = watchPath.resolve(folderName);
Set<String> validExtensions = Set.of(((String) config.get(folderName)).split(","));
if (Files.exists(folderPath) && Files.isDirectory(folderPath)) {
String[] validExtensions = ((String) config.get(folderName)).split(",");
folderFileExtMap.put(folderName, Set.of(validExtensions));
folderFileExtMap.put(folderName, validExtensions);
} else {
parsersWithoutFolder.addAll(validExtensions);
logger.warn("Directory '{}' does not exist in '{}'. Please check your configuration settings!",
folderName, OpenHAB.getConfigFolder());
}
@@ -147,6 +153,15 @@ public class FolderObserver implements WatchService.WatchEventListener {
this.activated = true;
logger.debug("{} has been activated", FolderObserver.class.getSimpleName());
logger.debug("{} elements in parsersWithoutFolder and {} elements in missingParsers",
parsersWithoutFolder.size(), missingParsers.size());
// process parsers without existing directory which were added during activation
for (String extension : parsersWithoutFolder) {
if (parsers.contains(extension) && !missingParsers.contains(extension)) {
readyService.markReady(new ReadyMarker(READYMARKER_TYPE, extension));
logger.debug("Marked extension '{}' as ready", extension);
}
}
// process ignored paths for missing parsers which were added during activation
for (String extension : missingParsers) {
if (parsers.contains(extension)) {