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>
38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# LibrePortal WebUI Atomic Write Utilities
|
|
# Provides atomic file writing functionality for web UI safety
|
|
|
|
# Atomic file write function for web UI safety
|
|
atomicWriteWebUI() {
|
|
local content="$1"
|
|
local target_file="$2"
|
|
local temp_file="${target_file}.tmp.$$"
|
|
|
|
# Every step runs as the path's owner so the manager-run runtime (Model A)
|
|
# can write the dockerinstall-owned WebUI/app files. Temp + rename share the
|
|
# target's directory, so the mv stays atomic (same filesystem, same owner).
|
|
local op="runInstallOp" wop="runInstallWrite"
|
|
if pathIsContainerData "$target_file"; then
|
|
op="runFileOp"; wop="runFileWrite"
|
|
fi
|
|
|
|
# Ensure directory exists
|
|
$op mkdir -p "$(dirname "$target_file")"
|
|
|
|
# Write to temp file first
|
|
printf '%s' "$content" | $wop "$temp_file"
|
|
|
|
# Set proper permissions
|
|
$op chmod 644 "$temp_file"
|
|
|
|
# Atomic rename (instantaneous - no partial reads)
|
|
$op mv "$temp_file" "$target_file"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ Atomic write successful: $target_file"
|
|
else
|
|
echo "✗ Atomic write failed: $target_file"
|
|
fi
|
|
}
|