fix(cli): skip subdirectories when reloading per-category configs

`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/<category>/` held only flat files.

The new backup system parks per-location configs at
`configs/backup/locations/<idx>/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 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
librelad 2026-05-26 21:23:18 +01:00
parent 1a8c377d7d
commit c290353fff

28
init.sh
View File

@ -465,20 +465,13 @@ initCheckConfigs() {
# Check if any config files exist (new structure) or old config files # Check if any config files exist (new structure) or old config files
local config_found=false 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 if [ -d "$configs_dir" ]; then
for category_dir in "$configs_dir"/*; do for category_dir in "$configs_dir"/*; do
if [ -d "$category_dir" ] && [ -f "$category_dir/.category" ]; then if [ -d "$category_dir" ] && [ -f "$category_dir/.category" ]; then
# Load new structure config files
for config_file in "$category_dir"/*; do for config_file in "$category_dir"/*; do
local should_load=true if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
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
source "$config_file" source "$config_file"
config_found=true config_found=true
fi fi
@ -1225,18 +1218,15 @@ reset_git_config() {
# Helper function to load config files in the libreportal command # Helper function to load config files in the libreportal command
commandReloadConfigs() { 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/<idx>/) — 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 for category_dir in "$configs_dir"/*; do
if [ -d "$category_dir" ] && [ -f "$category_dir/.category" ]; then if [ -d "$category_dir" ] && [ -f "$category_dir/.category" ]; then
for config_file in "$category_dir"/*; do for config_file in "$category_dir"/*; do
local should_load=true if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
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
source "$config_file" source "$config_file"
fi fi
done done