Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Template installation fixes #4591

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

seime
Copy link
Contributor

@seime seime commented Feb 10, 2025

Rule Template installation fixes

seime added 4 commits February 9, 2025 07:40
Signed-off-by: Arne Seime <[email protected]>
Trying to check if deleted files are hidden, are readable or are directories will result in IOExceptions on many file systems, so that no action will be taken for deletions.

Signed-off-by: Arne Seime <[email protected]>
@seime seime requested a review from a team as a code owner February 10, 2025 07:16
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/marketplace-versioning-with-embedded-resource/161421/202

@Nadahar Nadahar force-pushed the rule-templates-fixes branch from 7ff9145 to d07f695 Compare February 10, 2025 18:22
@Nadahar
Copy link
Contributor

Nadahar commented Feb 10, 2025

Ready for review/discussion.

This is a collaboration between @seime and me, so I'll add a bit of information.

There has been support for file-based rule templates (conf/automation/templates) in OH for many years, but it's been broken (not sure for how long), so it's probably unknown to most that it even exists. This is particularly handy for those making the rule templates. Today they have to upload their "work in progress" to the marketplace, install it and then test it. Rinse and repeat.

The reason it was broken is that the path used in the "file watcher" was wrong, so it responded by looking for the changed file in a different location and thus always failed to pick up anything. While we fixed this, we also found that there was another problem with the "file watcher" handling: The use of calls that potentially cause file system access as a way to filter out files, which fails for DELETE operations, because the file in question no longer exists.

To explain, it was for example checked if the file has hidden, and hidden files were filtered out. On Linux file systems, that work just fine, because you can deduct whether it's hidden from the file name itself (does it start with a .?). But, on other file systems, like NTFS, "hiddenness" is instead decided by file attributes stored in the file system. When trying to check this for a deleted file, a "file not found" IOException will be thrown and further processing halted.

The last commit in this PR is therefore strictly unrelated to rule templates, it just fixes the same issue in other places in core where the same problem was discovered.

Once the file-based rule templates were up and working, it turned out that only JSON was supported. Rule templates are often scripts like JavaScript. It's very inconvenient to write a whole script on one line separated by \n, so YAML support was desired in addition (as was already supported in the marketplace). Finally, the "parsers" for file and marketplace rule templates were "unified", giving the marketplace the additional functionality of supporting multiple rule templates in one file/add-on by putting them inside a JSON or YAML array.

@rkoshak
Copy link

rkoshak commented Feb 10, 2025

Solves #4589 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants