From c290353fff9fd3ea38cc6af745b315c45e3437aa Mon Sep 17 00:00:00 2001 From: librelad Date: Tue, 26 May 2026 21:23:18 +0100 Subject: [PATCH] fix(cli): skip subdirectories when reloading per-category configs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `commandReloadConfigs` (baked into /usr/local/lib/libreportal/libreportal) and `initCheckConfigs` both iterate every category dir's contents and `source` each entry, with only a string-suffix exclusion for `.category` markers — no `-f` test. That worked when `configs//` held only flat files. The new backup system parks per-location configs at `configs/backup/locations//location.config`, so `configs/backup/locations/` is now a SUBDIRECTORY inside the backup category. Sourcing it tripped: source: /libreportal-system/configs/backup/locations: is a directory …surfacing whenever something triggered a drift-driven config reload (e.g. during a `regen --force` or a release-mode re-fetch). The nested location configs already have their own dedicated loader (`sourceBackupLocations`) that handles the depth-3 walk; the category-level loop just needs to leave that subtree alone. Collapse both loops to the cleaner guard `initReloadConfigs` and `commandUpdateConfigOption` already use: if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then …which both excludes directories (the bug) and the `.category` markers in one shot, and drops a small pile of `should_load`/`filename` boilerplate along the way. Verified live on dev-ai (CLI tool dispatch now works through a drift-triggered reload without exiting non-zero). Co-Authored-By: Claude Opus 4.7 Signed-off-by: librelad --- init.sh | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/init.sh b/init.sh index 8851bba..8910fe4 100755 --- a/init.sh +++ b/init.sh @@ -465,20 +465,13 @@ initCheckConfigs() { # Check if any config files exist (new structure) or old config files local config_found=false - # Check for new structure + # Check for new structure. Skip subdirectories (per-location nested backup + # configs are loaded by their own helper) and the .category markers. if [ -d "$configs_dir" ]; then for category_dir in "$configs_dir"/*; do if [ -d "$category_dir" ] && [ -f "$category_dir/.category" ]; then - # Load new structure config files for config_file in "$category_dir"/*; do - local should_load=true - local filename=$(basename "$config_file") - # Skip .category files and excluded files (hardcoded) - if [[ "$config_file" =~ \.category$ ]]; then - should_load=false - fi - - if [ "$should_load" = true ]; then + if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then source "$config_file" config_found=true fi @@ -1225,18 +1218,15 @@ reset_git_config() { # Helper function to load config files in the libreportal command commandReloadConfigs() { - # Load new structure config files only + # Load new structure config files only. Skip subdirectories (e.g. the + # per-location nested backup configs/backup/locations//) — those are + # loaded by their own sourceBackupLocations helper. Skip the .category + # marker files too. Matches the guard initReloadConfigs / commandUpdateConfigOption + # already use. for category_dir in "$configs_dir"/*; do if [ -d "$category_dir" ] && [ -f "$category_dir/.category" ]; then for config_file in "$category_dir"/*; do - local should_load=true - local filename=$(basename "$config_file") - # Skip .category files and excluded files (hardcoded for now) - if [[ "$config_file" =~ \.category$ ]]; then - should_load=false - fi - - if [ "$should_load" = true ]; then + if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then source "$config_file" fi done