Skip to content

Commit 80b3fa8

Browse files
author
linux_name2
committed
gc rm: warn about orphaned home subvolumes before deletion
1 parent 25353e4 commit 80b3fa8

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎bin/atomic-gc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ case "$COMMAND" in
8989
done
9090
if [[ "$YES" -eq 0 && "$DRY_RUN" -eq 0 ]]; then
9191
echo "Will delete: ${ARGS[*]}"
92+
warn_orphan_homes "${ARGS[@]}"
9293
read -rp "Continue? [y/N] " answer
9394
[[ "$answer" =~ ^[Yy] ]] || { echo "Aborted"; exit 0; }
95+
elif [[ "$DRY_RUN" -eq 1 ]]; then
96+
warn_orphan_homes "${ARGS[@]}"
9497
fi
9598
for gen_id in "${ARGS[@]}"; do
9699
delete_generation "$gen_id" "$DRY_RUN"

‎lib/atomic/common.sh‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,47 @@ garbage_collect() {
599599
echo ":: Garbage collection done"
600600
}
601601

602+
# ── Orphan home warning ──────────────────────────────────────────────
603+
# Warns if deleting the given generation(s) would leave home-<tag>
604+
# subvolumes with no remaining generations referencing their tag.
605+
# Args: gen_id [gen_id ...]
606+
607+
warn_orphan_homes() {
608+
local -a del_ids=("$@")
609+
local -A seen_tags=()
610+
local gen_id tag uki_file uki_gen del_id
611+
612+
for gen_id in "${del_ids[@]}"; do
613+
[[ "$gen_id" =~ ^[0-9]{8}-[0-9]{6}-(.+)$ ]] || continue
614+
tag="${BASH_REMATCH[1]}"
615+
[[ -z "${seen_tags[$tag]+x}" ]] || continue
616+
seen_tags[$tag]=1
617+
[[ -d "${BTRFS_MOUNT}/home-${tag}" ]] || continue
618+
619+
# Any generation NOT in the delete list that also uses this tag?
620+
local has_other=0
621+
for uki_file in "${ESP}/EFI/Linux/arch-"*.efi; do
622+
[[ -e "$uki_file" ]] || continue
623+
uki_gen="${uki_file##*/}"
624+
uki_gen="${uki_gen#arch-}"; uki_gen="${uki_gen%.efi}"
625+
# Extract tag from this UKI's gen_id
626+
local uki_tag=""
627+
[[ "$uki_gen" =~ ^[0-9]{8}-[0-9]{6}-(.+)$ ]] && uki_tag="${BASH_REMATCH[1]}"
628+
[[ "$uki_tag" == "$tag" ]] || continue
629+
# Same tag — is this UKI being deleted?
630+
local in_list=0
631+
for del_id in "${del_ids[@]}"; do
632+
[[ "$uki_gen" == "$del_id" ]] && { in_list=1; break; }
633+
done
634+
[[ $in_list -eq 0 ]] && { has_other=1; break; }
635+
done
636+
637+
[[ $has_other -eq 0 ]] || continue
638+
echo "NOTE: home-${tag} will become orphaned (not auto-deleted)"
639+
echo " To remove: btrfs subvolume delete ${BTRFS_MOUNT}/home-${tag}"
640+
done
641+
}
642+
602643
delete_generation() {
603644
local gen_id="$1"
604645
local dry_run="${2:-0}"

0 commit comments

Comments
 (0)