From ef1dcc247a2d1df7b160af5bba9cf63591ce65f9 Mon Sep 17 00:00:00 2001 From: pi-os3 Date: Sat, 7 Nov 2026 19:03:42 -0400 Subject: [PATCH 1/2] prepare-stick: refuse a staging that will not fit, fsck-and-retry the resize, and prove the staged bytes engine#1374, from the c32 stage step: the data partition was 58.1 GiB but the filesystem still 7.8 GiB, so 6.6 of 7.9 GB of models landed and sd_turbo.safetensors was truncated - caught only by byte-comparing the tree against its source, because a partially merged tree cannot be proven by du -sb. It was the second occurrence of the resize failing. Four things in os/mini/prepare-stick.sh, each of which a person had to work around by hand on c32: 1. No free-space preflight. The staging loops cp one file at a time and learn about a full filesystem from a copy that fails PART WAY, leaving a truncated file behind. Now the bytes to stage (models + 5 % headroom for ext4 metadata) are compared with df --output=avail on the mounted data partition BEFORE anything is written, and the refusal names both numbers and the likely cause ("the data partition or its filesystem did not grow"). 2. A failed grow is silent by design ("a failure leaves a working 2 GiB stick") and that fallback is right - but nothing then checked that the staging still fit. With (1) it does, so the fallback is honest: the stick stays usable and the staging refuses with a reason instead of truncating. 3. resize2fs ran with no e2fsck and no retry, though an ext4 needing journal recovery makes it refuse - the operator's c32 workaround was exactly "e2fsck -f, then resize2fs". The tool now does that itself, once, on the unmounted partition. 4. The success line reported the PARTITION size as the filesystem size ("now holds 58.1 GiB of ext4"), which is what made the c32 failure confusing: the partition really had grown while the fs had not. It now reads the filesystem's own Block count and Block size and prints both. And the staging is now PROVEN rather than assumed: cmp -s per model file and diff -r -q per NPU directory, because "cp returned 0" is not evidence - measured on main, a 20 GiB model was "prepared and proved" onto an 8 GiB partition by a sparse copy that wrote no blocks, and the exit code, df and the directory entry all said fine. Measured, on copies of the c32 image (6.6 GiB free on its data partition): main + a 20 GiB model -> "is prepared and proved", rc=0, models/huge.gguf listed at 21474836480 B with 0 blocks written and the free space unchanged <- the bug, and it is not visible from df this commit + the same -> "the staging needs 21504 MiB (models + 5 % headroom) but /dev/loop18p2 has 6281 MiB free: ... Refusing rather than truncating a model file (engine#1374)" and nothing written this commit + a 1 MiB model -> "fit staging needs 1 MiB, 6281 MiB free" / "models/small.gguf (1048576 bytes, byte-identical to the source)" / "prepared and proved", rc=0; cmp against the source outside the script agrees proof logic, unit-tested -> cmp catches a truncated copy; diff -r catches an extra file; both pass on an identical copy bash -n + shellcheck -S warning clean, tools/copyright.py --check rc 0, one file. No gate change: the release gates already byte-verify the staged tree (that is how c32's truncation was found), and they should not be the thing that discovers it. --- os/mini/prepare-stick.sh | 62 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/os/mini/prepare-stick.sh b/os/mini/prepare-stick.sh index 37b42c5d3..c3dafb5f3 100755 --- a/os/mini/prepare-stick.sh +++ b/os/mini/prepare-stick.sh @@ -227,10 +227,29 @@ printf 'node %s\n' "$PART" # ext4 grows in place; the filesystem is not mounted yet, so this is an offline resize - the quick path. if [ "$GREW" = 1 ]; then command -v resize2fs >/dev/null 2>&1 || die "resize2fs is missing; the data partition grew but its filesystem did not" - resize2fs "$PART" >/dev/null 2>&1 || die "resize2fs failed on $PART; the partition grew but the filesystem did not" - printf 'grown %s now holds %.1f GiB of ext4 (was %.1f GiB)\n' "$PART" \ - "$(awk -v s="$SIZE" 'BEGIN { printf "%.1f", s * 512 / 1073741824 }')" \ - "$(awk -v s="$SIZE0" 'BEGIN { printf "%.1f", s * 512 / 1073741824 }')" + # engine#1374: an ext4 that needs journal recovery makes resize2fs refuse, and the operator's workaround on c32 was exactly + # `e2fsck -f` then resize2fs - the tool should do that itself rather than hand it back as a failed stage. The partition is not + # mounted here, so the fsck is offline and safe. + if ! resize2fs "$PART" >/dev/null 2>&1; then + printf 'grow resize2fs refused %s; fscking it offline and retrying once (engine#1374)\n' "$PART" + command -v e2fsck >/dev/null 2>&1 || die "resize2fs failed on $PART and e2fsck is missing; the partition grew but the filesystem did not" + e2fsck -f -y "$PART" >/dev/null 2>&1 || die "e2fsck failed on $PART; the partition grew but the filesystem did not" + resize2fs "$PART" >/dev/null 2>&1 || die "resize2fs failed on $PART even after an offline fsck; the partition grew but the filesystem did not" + fi + # the SIZE in the partition table is the PARTITION's; what a person needs to know is what the FILESYSTEM can hold, which is + # the number whose absence made the c32 failure confusing (58.1 GiB partition, 7.8 GiB fs, and a message that claimed both) + fsblocks=$(dumpe2fs -h "$PART" 2>/dev/null | sed -n 's/^Block count:[[:space:]]*//p' | head -1) + fsbytes=$(dumpe2fs -h "$PART" 2>/dev/null | sed -n 's/^Block size:[[:space:]]*//p' | head -1) + if [ -n "${fsblocks:-}" ] && [ -n "${fsbytes:-}" ]; then + printf 'grown %s filesystem now holds %.1f GiB of ext4 (was %.1f GiB); partition %.1f GiB\n' "$PART" \ + "$(awk -v b="$fsblocks" -v s="$fsbytes" 'BEGIN { print b * s / 1073741824 }')" \ + "$(awk -v s="$SIZE0" 'BEGIN { print s * 512 / 1073741824 }')" \ + "$(awk -v s="$SIZE" 'BEGIN { print s * 512 / 1073741824 }')" + else + printf 'grown %s partition now holds %.1f GiB (was %.1f GiB); the filesystem size could not be read\n' "$PART" \ + "$(awk -v s="$SIZE" 'BEGIN { print s * 512 / 1073741824 }')" \ + "$(awk -v s="$SIZE0" 'BEGIN { print s * 512 / 1073741824 }')" + fi fi # ---- mount --------------------------------------------------------------------------------------- @@ -311,12 +330,41 @@ if [ "$CHECK" = 0 ]; then esac write_key "$KEY" fi + # engine#1374: refuse BEFORE writing if the staging will not fit. Without this the first sign of a data partition that did not + # grow (or whose filesystem did not resize) is a `cp` that fails part way - and the failure leaves a TRUNCATED model file + # behind, which `du -sb` on a partially merged tree does not reliably show. Measured on c32: 6.6 of 7.9 GB landed and + # sd_turbo.safetensors was truncated; only a byte comparison against the source found it. 5 % headroom covers ext4's + # metadata for many small files; the number is a refusal threshold, not a reservation. + want=0 + for m in $MODELS; do + [ -s "$m" ] || die "model $m is empty or missing" + sz=$(stat -Lc %s "$m" 2>/dev/null || echo 0) + want=$((want + sz)) + done + for d in $NPUMODELS; do + sz=$(du -sb "$d" 2>/dev/null | cut -f1) + want=$((want + ${sz:-0})) + done + if [ "$want" -gt 0 ]; then + avail=$(df -B1 --output=avail "$MNT" 2>/dev/null | awk 'NR==2 {print $1}') + need=$((want + want / 20)) + if [ -z "${avail:-}" ] || [ "$avail" -lt "$need" ]; then + die "the staging needs $((need / 1048576)) MiB (models + 5 % headroom) but $PART has $(( ${avail:-0} / 1048576 )) MiB free: the data partition or its filesystem did not grow. Refusing rather than truncating a model file (engine#1374)" + fi + printf 'fit staging needs %s MiB, %s MiB free on %s\n' "$((need / 1048576))" "$((avail / 1048576))" "$PART" + fi for m in $MODELS; do [ -s "$m" ] || die "model $m is empty or missing" [ -d "$MNT/models" ] || mkdir -p "$MNT/models" cp -f "$m" "$MNT/models/$(basename "$m")" || die "could not copy $m into $MNT/models" chown 0:0 "$MNT/models" "$MNT/models/$(basename "$m")" 2>/dev/null - printf 'model models/%s (%s bytes)\n' "$(basename "$m")" "$(stat -Lc %s "$m")" + # engine#1374: prove the staged bytes, do not assume them. `cp` returning 0 is not evidence that what is on the medium is + # what was asked for - measured on main: a 20 GiB model was "prepared and proved" onto an 8 GiB partition with zero blocks + # written, and neither the exit code, `df`, nor the directory entry could tell. cmp is byte-exact and reads neither twice + # more than the copy did. + cmp -s "$m" "$MNT/models/$(basename "$m")" || + die "the staged models/$(basename "$m") is not byte-identical to $m (a short write, a truncated copy, or the source changed while staging)" + printf 'model models/%s (%s bytes, byte-identical to the source)\n' "$(basename "$m")" "$(stat -Lc %s "$m")" done for d in $NPUMODELS; do name=${d%/}; name=${name##*/} @@ -326,6 +374,10 @@ if [ "$CHECK" = 0 ]; then # -L: on a build box the model directory is symlinks into the FLM install; the stick needs the bytes cp -fRL "$d"/. "$MNT/models/$name"/ || die "could not copy the NPU model $d into $MNT/models/$name" chown -R 0:0 "$MNT/models/$name" 2>/dev/null + # the same proof for a directory of files: every staged file byte-identical to its source (diff -r compares contents and + # reports a missing or extra file as a difference too) + diff -r -q "$d" "$MNT/models/$name" > /dev/null 2>&1 || + die "the staged models/$name is not byte-identical to $d (run: diff -r $d $MNT/models/$name)" printf 'npu models/%s (%s files, %s bytes)\n' "$name" \ "$(find "$MNT/models/$name" -type f | wc -l)" "$(du -sb "$MNT/models/$name" | cut -f1)" done From 1b3c83ac00dd028b477a10b09373ce99affb2658 Mon Sep 17 00:00:00 2001 From: pi-os3 Date: Sat, 7 Nov 2026 19:23:50 -0400 Subject: [PATCH 2/2] 1bit-update: the machine's own save layer is not "another machine's state", so a second update works engine#1376. `1bit-update` let an installed machine take ONE in-place update; the second was refused on the machine's own save layer. The mechanism, from the issue: `save_slot` is the slot holding the REAL save directory, and the update only ever links that layer into the other slot - so `save_slot` stays `1bit` forever. After update 1 the machine runs `psubdir=1bit-alt`, which makes update 2's target `1bit` - the very slot the layer lives in - and the guard that refuses "a slot that already owns a save layer" walked straight into the machine's own save: DIE: /1bit already holds a save layer (upup64rsave): two layers cannot be merged by an update Three fixes, all in the same file: * the target guard compares the FILE, not the name: a real directory there that is the same device+inode as $DATA/$save_slot/$savename is this machine's own layer and is kept; only a genuinely different layer is refused, and the refusal now names which one is the machine's. * the link step does not run when target IS the slot the layer lives in - linking there would create the `upup64rsave/upup64rsave` self-reference that #1334's review found - and does not run at all when the machine has no layer, where the old line would have run `ln -sfn "../$save_slot/$savename"` with both empty (a link to the slot's own parent). * the layer scan takes the ACTIVE slot's layer first. It used to scan both slots and let the last real directory win, so a foreign layer sitting in the other slot could be adopted as this machine's. And 1bit-update-selftest.sh, because update-gate.sh cannot see any of this - its boots are update -> boot alt -> rollback -> boot original, so it never runs a second update. The selftest builds the four shapes the real machine has at that moment on fake /data trees (no VM, no disk), lifts the three blocks out of the script under test between its own section markers, and fails loudly if the extraction finds nothing rather than passing nothing. Measured, the same selftest against both versions: main (f559162) 4 passed / 3 failed - A the second update refused, C the scan adopted the foreign layer, D the empty-savename link tried `ln -sfn ../..` and failed the update this commit 7 passed / 0 failed Two of my own defects found by writing that test, both fixed here: the empty-savename link (a real latent bug in main, above) and the extraction, which first used fragments and cut a for-loop mid-body - the selftest failed loudly, which is why the extraction is now two contiguous ranges. The fixture for the source tree must also be non-empty, because the script's own pre-check is -s and an empty fixture failed a check unrelated to the case under test. --- os/v3/puppy/1bit-update-selftest.sh | 165 ++++++++++++++++++++ os/v3/puppy/embed/usr/local/bin/1bit-update | 26 ++- 2 files changed, 187 insertions(+), 4 deletions(-) create mode 100755 os/v3/puppy/1bit-update-selftest.sh diff --git a/os/v3/puppy/1bit-update-selftest.sh b/os/v3/puppy/1bit-update-selftest.sh new file mode 100755 index 000000000..a391c779a --- /dev/null +++ b/os/v3/puppy/1bit-update-selftest.sh @@ -0,0 +1,165 @@ +#!/bin/sh +# Copyright 2026 bong-water-water-bong +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# 1bit-update-selftest.sh - the second-update logic of 1bit-update, on fake /data trees, with no VM and no disk. +# +# engine#1376: `1bit-update` let an installed machine take ONE update. The second was refused on the machine's own save +# layer, because after update 1 the machine runs the alt slot while the layer still lives in /1bit - so the second update's +# target IS the slot holding the real layer, and the "a slot that already owns a save layer is another machine's state" +# guard walked into it. `update-gate.sh` cannot see this: its boots are update -> boot alt -> rollback -> boot original, so it +# never runs a second update. +# +# The four cases, each on a tree built to be the shape the real machine has at that moment: +# +# A one layer, linked into the other slot (what update 1 leaves behind) -> must PROCEED: the layer found in the target +# slot is the same file as this machine's, so it is kept, the layer is not moved, and NO self-referencing link is created +# (the latent defect #1334's review found: linking a layer into the slot it really lives in) +# B a genuinely different layer in the target slot -> must REFUSE, naming which is the machine's own +# C a foreign real layer in the OTHER slot, the machine's own in the active -> the scan must pick the ACTIVE slot's layer, +# not the last real directory it happens to see +# D no layer at all -> must proceed (nothing to keep, nothing to link) +# +# The three blocks under test are lifted out of the script itself, between the section markers it already carries, so this +# tests the shipped code rather than a copy of it. If the markers ever move, the extraction is empty and the selftest fails +# loudly (case 0) instead of silently passing nothing. +# +# Usage: 1bit-update-selftest.sh [path to 1bit-update] Exit: 0 all cases pass, 1 a case failed, 2 could not run. +set -u + +here=$(cd "$(dirname "$0")" && pwd) +script=${1:-$here/embed/usr/local/bin/1bit-update} +[ -f "$script" ] || { echo "1bit-update-selftest: no such script: $script" >&2; exit 2; } +command -v mktemp > /dev/null 2>&1 || { echo "1bit-update-selftest: mktemp is missing" >&2; exit 2; } + +work=$(mktemp -d "${TMPDIR:-/tmp}/1bu-selftest.XXXXXX") || exit 2 +trap 'chmod -R u+w "$work" 2> /dev/null; rm -rf "$work"' EXIT + +# ── lift the three blocks out of the script under test ──────────────────────────────────────────────────────────────── +blocks=$work/blocks.sh +awk ' + # two contiguous blocks, each ending at the same marker: the scan, then the guard + write + link. Fragment-based + # extraction (stopping at a line that appears twice) cut a for-loop mid-body and produced a syntax error - the failure + # was loud, but it wasted a run; contiguous ranges cannot do that. + /^save_slot=$/ { scan = 1 } + scan && /^# ── GRUB/ { scan = 0 } + scan { print } + + /^# a slot that already owns a save layer/ { act = 1 } + act && /^# ── GRUB/ { act = 0; print "" } + act { print } +' "$script" > "$blocks" + +fail=0 ok=0 +check() { # [grep for a line that must appear] + want=$1 name=$2 data=$3 active=$4 target=$5 say_grep=${6:-} + out=$(env -i PATH=/usr/bin:/bin DATA="$data" active="$active" target="$target" ALT=1bit-alt \ + LOG="$work/log" BLOCKS="$blocks" SELFTEST_SRC="$SELFTEST_SRC" sh "$work/harness.sh" 2>&1) + rc=$? + case $want in + ok) + if [ "$rc" = 0 ] && { [ -z "$say_grep" ] || printf '%s' "$out" | grep -q "$say_grep"; }; then + printf 'PASS %s\n' "$name"; ok=$((ok + 1)) + else + printf 'FAIL %s: expected success%s, got rc=%s\n%s\n' "$name" "${say_grep:+ and '$say_grep'}" "$rc" "$out" + fail=$((fail + 1)) + fi + ;; + die) + if [ "$rc" = 2 ] && printf '%s' "$out" | grep -q 'DIE(rc 2)'; then + printf 'PASS %s\n' "$name"; ok=$((ok + 1)) + else + printf 'FAIL %s: expected the refusal (rc 2), got rc=%s\n%s\n' "$name" "$rc" "$out" + fail=$((fail + 1)) + fi + ;; + esac + [ -f "$work/log" ] && : > "$work/log" +} + +# the harness the blocks run inside: the two commands they call, and a source tree with one file to copy +cat > "$work/harness.sh" <<'H' +say() { printf 'say: %s\n' "$*"; } +die() { printf 'DIE(rc 2): %s\n' "$*" >&2; exit 2; } +fail() { printf 'FAIL(rc 3): %s\n' "$*" >&2; exit 3; } +src=$SELFTEST_SRC +need="vmlinuz" +. "$BLOCKS" +H +SELFTEST_SRC=$work/src +export SELFTEST_SRC +mkdir -p "$SELFTEST_SRC" +# NOT empty: the script's own pre-check is `[ -s "$src/$f" ]` (size > 0), so an empty fixture fails a check that has +# nothing to do with the case under test - measured, that is how this line was found +printf 'vmlinuz fixture\n' > "$SELFTEST_SRC/vmlinuz" + +mk() { # + d=$1 + rm -rf "$d" + mkdir -p "$d/1bit" "$d/1bit-alt" + case $2 in + linked) mkdir -p "$d/1bit/upup64rsave"; ln -s ../1bit/upup64rsave "$d/1bit-alt/upup64rsave" ;; + foreign) mkdir -p "$d/1bit/foreignsave"; ln -s ../1bit/foreignsave "$d/1bit-alt/foreignsave" ;; + two) mkdir -p "$d/1bit/foreignsave" "$d/1bit-alt/mysave" ;; + none) : ;; + esac + mkdir -p "$d/1bit" +} + +# ── case 0: the extraction itself ─────────────────────────────────────────────────────────────────────────────────── +if [ -s "$blocks" ] && grep -q 'savename=' "$blocks" && grep -q 'ln -sfn' "$blocks"; then + printf 'PASS %s\n' 'the three blocks were found in the script under test'; ok=$((ok + 1)) +else + printf 'FAIL %s: the marker-based extraction found nothing in %s - the selftest would pass nothing\n' 'extraction' "$script" + fail=$((fail + 1)) +fi + +# ── A: the shape update 1 leaves behind - must proceed, keep the layer, create no self-link ───────────────────────── +mk "$work/a" linked +check ok 'A: second update proceeds on one linked layer' "$work/a" 1bit-alt 1bit 'own layer' +if [ -e "$work/a/1bit/upup64rsave/upup64rsave" ]; then + printf 'FAIL %s: a self-referencing upup64rsave/upup64rsave was created inside the layer\n' 'A: no self-link' + fail=$((fail + 1)) +else + printf 'PASS %s\n' 'A: no self-referencing link inside the layer'; ok=$((ok + 1)) +fi +if [ -f "$work/a/1bit/upup64rsave/.keep" ] || [ -d "$work/a/1bit/upup64rsave" ]; then + printf 'PASS %s\n' 'A: the layer is still where it lives'; ok=$((ok + 1)) +else + printf 'FAIL %s\n' 'A: the layer directory is gone'; fail=$((fail + 1)) +fi + +# ── B: a genuinely different layer in the target slot - must refuse ────────────────────────────────────────────── +mk "$work/b" two +check die 'B: a foreign layer in the target slot is refused' "$work/b" 1bit-alt 1bit + +# ── C: a foreign real layer in the other slot - the scan must pick the ACTIVE slot's layer ──────────────────────── +mk "$work/c" two +out=$(env -i PATH=/usr/bin:/bin DATA="$work/c" active=1bit-alt target=1bit ALT=1bit-alt LOG="$work/log" \ + BLOCKS="$blocks" SELFTEST_SRC="$SELFTEST_SRC" sh "$work/harness.sh" 2>&1) +if printf '%s' "$out" | grep -q 'not this machine.s (1bit-alt/mysave)'; then + printf 'PASS %s\n' "C: the scan picked the active slot's layer, not the foreign one"; ok=$((ok + 1)) +else + printf 'FAIL %s\n%s\n' 'C: the scan did not name 1bit-alt/mysave as the machine layer' "$out" + fail=$((fail + 1)) +fi + +# ── D: no layer at all - must proceed ──────────────────────────────────────────────────────────────────────────── +mk "$work/d" none +check ok 'D: an update with no layer anywhere proceeds' "$work/d" 1bit 1bit-alt + +printf '\n1bit-update-selftest: %s passed, %s failed\n' "$ok" "$fail" +[ "$fail" = 0 ] || exit 1 +echo "RESULT: PASS" diff --git a/os/v3/puppy/embed/usr/local/bin/1bit-update b/os/v3/puppy/embed/usr/local/bin/1bit-update index 837c4fa9b..bda7a33b0 100755 --- a/os/v3/puppy/embed/usr/local/bin/1bit-update +++ b/os/v3/puppy/embed/usr/local/bin/1bit-update @@ -95,13 +95,16 @@ done [ -n "$esp" ] || die "no 1BIT-OS partition on $bootdisk: this machine did not boot from an installed disk" save_slot= savename= -for d in "$DATA"/1bit "$DATA"/"$ALT"; do +# engine#1376: the ACTIVE slot's layer is the one this machine is running, so it is found first and wins. Scanning both slots +# and letting the last real directory win meant a foreign layer in the other slot could be adopted as "this machine's layer". +for d in "$DATA/$active" "$DATA/1bit" "$DATA/$ALT"; do [ -d "$d" ] || continue for s in "$d"/*save*; do [ -e "$s" ] || continue # -L: a symlink to the layer counts, but only a REAL directory is where the layer lives - if [ -d "$s" ] && [ ! -L "$s" ]; then save_slot=$(basename "$d"); savename=$(basename "$s"); fi + if [ -d "$s" ] && [ ! -L "$s" ]; then save_slot=$(basename "$d"); savename=$(basename "$s"); break; fi done + [ -n "$savename" ] && break done # ── GRUB: read the config, find a slot's entries, write the default ────────────────────────────────────────── @@ -235,7 +238,11 @@ freek=$(df -Pk "$DATA" | awk 'NR == 2 { print $4 }') for s in "$DATA/$target"/*save*; do [ -e "$s" ] || continue if [ -d "$s" ] && [ ! -L "$s" ]; then - die "/$target already holds a save layer ($(basename "$s")): two layers cannot be merged by an update - pick the slot by hand if that is really what you want" + if [ -n "$savename" ] && [ "$s" -ef "$DATA/$save_slot/$savename" ]; then + say " $(basename "$s") in /$target is this machine's own layer (same file as /$save_slot/$savename): kept" + continue + fi + die "/$target already holds a save layer ($(basename "$s")) that is not this machine's ($save_slot/$savename): two layers cannot be merged by an update - pick the slot by hand if that is really what you want" fi rm -f "$s" done @@ -246,7 +253,18 @@ for f in $need; do cp -f "$src/$f" "$DATA/$target/$f" >> "$LOG" 2>&1 || fail "copying $f into /$target failed" done [ -s "$src/SHA256SUMS" ] && cp -f "$src/SHA256SUMS" "$DATA/$target/SHA256SUMS" 2> /dev/null -ln -sfn "../$save_slot/$savename" "$DATA/$target/$savename" || fail "cannot link the save layer into /$target" +if [ -z "$savename" ]; then + # engine#1376: a machine with no save layer at all (a fresh installed root, or a --check tree) has nothing to link, and + # the old line would have run `ln -sfn "../$save_slot/$savename"` with both empty - i.e. linked the target slot to its own + # parent. Found by this selftest's no-layer case. + say " no save layer on this machine: nothing to link into /$target" +elif [ "$DATA/$target/$savename" -ef "$DATA/$save_slot/$savename" ] 2> /dev/null; then + # already this machine's layer where it belongs (target is the slot the layer really lives in): nothing to link, and + # linking here would point the layer at itself + say " save layer stays where it is (/$save_slot/$savename); /$target needs no link" +else + ln -sfn "../$save_slot/$savename" "$DATA/$target/$savename" || fail "cannot link the save layer into /$target" +fi for f in $need; do cmp -s "$src/$f" "$DATA/$target/$f" || fail "/$target/$f does not match the source after copying" done