#!/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