librelad 2d24a764a8 refactor(storage): route elevation tests and the WebUI tree through paths.sh
Two mechanical sweeps, no behaviour change on a single-root install.

The 14 `[[ "$p" == "$containers_dir"* ]]` prefix tests that decide
manager-vs-container-user elevation become pathIsContainerData, so a file
on a second storage root is no longer misclassified as manager-owned —
which would have written it with the wrong owner and failed later, far
from the cause. The 65 references to the WebUI's own tree become
webuiDir(), which is pinned to the primary root by design.

Two traps found while doing it:

run_privileged.sh is sourced directly by init.sh without paths.sh, so it
needs a fallback. Defining one named pathIsContainerData was wrong:
generate_function_manifest.sh indexes top-level definitions, and the
resulting autoload stub would have shadowed the real multi-root
implementation with the primary-only fallback — silently classifying
every file on a second disk as manager-owned, which is exactly the bug
this sweep exists to prevent. Renamed to _runCfgIsContainerPath, which
delegates when the real one is loaded.

setup_lock.sh built its path in a top-level assignment, so it was
evaluated at source time and needed the file flagged eager. Made it a
function instead: the path resolves on call, and the file drops off
LP_EAGER_FILES entirely.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-24 04:04:19 +01:00

34 lines
1.0 KiB
Bash

#!/bin/bash
# Generate data/peers/generated/peers.json — drives the /peers WebUI page and
# is also read by the /backup/migrate tab to overlay friendly names on top of
# bare hostnames.
#
# This is just peerList wrapped with a generated_at envelope; no extra logic.
webuiGeneratePeers()
{
local output_dir="$(webuiDir)/frontend/data/peers/generated"
local output_file="$output_dir/peers.json"
runFileOp mkdir -p "$output_dir"
local generated_at
generated_at=$(date -Iseconds)
local peers
peers=$(peerList 2>/dev/null)
[[ -z "$peers" ]] && peers='[]'
# Pipe the JSON straight through runFileWrite — the previous
# `cat > "$temp_file"` redirect failed because $temp_file sits in the
# dockerinstall-owned data/ tree and the manager can't open it for write.
# The mv that followed then errored with "No such file or directory".
runFileWrite "$output_file" <<EOF
{
"generated_at": "$generated_at",
"peers": $peers
}
EOF
runFileOp chmod 644 "$output_file" 2>/dev/null || true
}