LibrePortal/scripts/dev/lp-storage-default-test
librelad 49c463a996 feat(storage): a default location, so one choice places every future app
Per-app placement worked but had no default: a box with a big second disk
meant setting CFG_<APP>_STORAGE on every app individually. CFG_STORAGE_DEFAULT
fixes that, and the wizard asks for it in one line.

CFG_<APP>_STORAGE now has three states rather than two, and the third is
the point:

  <name>    this app goes there, whatever the default says
  primary   this app goes on the install-time root, explicitly
  default   no opinion — follow CFG_STORAGE_DEFAULT

Templates ship "default", so the setting reaches every app without
touching 37 configs, while an app that was deliberately placed keeps its
placement. "primary" is new, and needed: without it there was no way to
say "keep this one on the system disk" once the global default moved.

A default naming a location that has since been removed falls back to the
primary root rather than refusing — a disk that got unregistered must not
make apps un-installable.

The wizard asks only once a second drive is ticked; with nothing ticked
there is one possible answer and a control would be furniture. It sets a
default, not a placement, and the value stored is the location NAME, so it
survives the disk being remounted elsewhere.

scripts/dev/lp-storage-default-test covers all three states plus the
removed-location fallback.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 03:31:13 +01:00

37 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Covers CFG_STORAGE_DEFAULT's three states: a named location wins, "primary"
# pins to the install-time root, and "default" (what every app template ships)
# inherits the global setting — which is what lets one choice at setup place
# every future app without editing 37 configs.
R="$(cd "$(dirname "$0")/../.." && pwd)"
B=$(mktemp -d); trap 'rm -rf "$B"' EXIT
export LP_SYSTEM_DIR="$B/sys" LP_CONTAINERS_DIR="$B/primary" LP_BACKUPS_DIR="$B/bk"
export LP_STORAGE_REGISTRY="$B/storage.roots"
mkdir -p "$B/primary" "$B/big" "$B/sys/configs"
printf '2\t%s\t0:0\tuuid2\n' "$B/big" > "$B/storage.roots"
: > "$B/big/.libreportal-storage"
source "$R/scripts/source/paths.sh"
CFG_STORAGE_LOC_2_NAME=bigdisk
fail=0
chk(){ [[ "$2" == "$3" ]] && echo " ok $1" || { echo " FAIL $1: got '$2' want '$3'"; fail=1; }; }
echo "--- global default = primary (out of the box) ---"
CFG_STORAGE_DEFAULT=primary; storageCacheReset
chk "app with no opinion" "$(appDir newapp)" "$B/primary/newapp"
echo "--- global default = bigdisk ---"
CFG_STORAGE_DEFAULT=bigdisk; storageCacheReset
chk "app inherits the default" "$(appDir newapp)" "$B/big/newapp"
CFG_NEWAPP_STORAGE=default; storageCacheReset
chk "explicit 'default' inherits too" "$(appDir newapp)" "$B/big/newapp"
CFG_NEWAPP_STORAGE=primary; storageCacheReset
chk "explicit 'primary' overrides" "$(appDir newapp)" "$B/primary/newapp"
CFG_NEWAPP_STORAGE=bigdisk; storageCacheReset
chk "explicit name wins" "$(appDir newapp)" "$B/big/newapp"
echo "--- a default naming a location that was removed ---"
CFG_STORAGE_DEFAULT=ghostdisk; unset CFG_NEWAPP_STORAGE; storageCacheReset
chk "falls back, never refuses" "$(appDir newapp)" "$B/primary/newapp"
echo; [[ $fail -eq 0 ]] && echo "ALL PASS" || echo "FAILURES"; exit $fail