fix(felhom-wipe): remove empty bind mount point dirs after nuclear wipe

After unmounting /mnt/hdd_1 (bind) and /mnt/.felhom-raw/hdd_1 (raw),
the /mnt/hdd_1 directory remained as an empty directory. Now rmdir is
called on each bind target after unmounting so the mount point is fully
cleaned up. rmdir (not rm -rf) ensures we only remove truly empty dirs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 12:06:19 +01:00
parent a2848f6d67
commit 5c455755a5
+13 -3
View File
@@ -258,7 +258,7 @@ print_plan() {
local bind_target
bind_target=$(grep -E "^/mnt/\.felhom-raw/${label}/" /etc/fstab 2>/dev/null | awk '{print $2}' | head -1 || true)
if [ -n "$bind_target" ]; then
echo -e " ${RED}umount${NC} ${bind_target} (bind) → ${rmp} (raw)"
echo -e " ${RED}umount + rmdir${NC} ${bind_target} (bind) → ${rmp} (raw)"
else
echo -e " ${RED}umount${NC} ${rmp} (raw, no bind found)"
fi
@@ -311,8 +311,9 @@ cleanup_raw_mounts() {
info "Cleaning up raw helper mounts (/mnt/.felhom-raw/)..."
# 1. Unmount bind mounts whose source is inside .felhom-raw (field 1 matches)
# Collect targets first so we can rmdir them after unmounting.
local bind_targets=""
if [ -f /etc/fstab ]; then
local bind_targets
bind_targets=$(grep -E '^/mnt/\.felhom-raw/' /etc/fstab | awk '{print $2}' || true)
for mp in $bind_targets; do
if mountpoint -q "$mp" 2>/dev/null; then
@@ -336,8 +337,17 @@ cleanup_raw_mounts() {
sed -i '\|\.felhom-raw|d' /etc/fstab && info " Removed .felhom-raw entries from /etc/fstab"
fi
# 4. Remove directory — safe now that mounts are gone
# 4. Remove /mnt/.felhom-raw/ — safe now that mounts are gone
rm -rf /mnt/.felhom-raw && info " Removed: /mnt/.felhom-raw/"
# 5. Remove the now-empty bind target directories (e.g. /mnt/hdd_1).
# Use rmdir so we only remove them if truly empty — never touch user data.
for mp in $bind_targets; do
if [ -d "$mp" ]; then
rmdir "$mp" 2>/dev/null && info " Removed mount point: $mp" \
|| warn " Could not remove (not empty?): $mp"
fi
done
}
# --- Wipe Functions ---