From 53cd2d35f188e6a2c8e47385368c6c6a7c0f2e6b Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 24 Mar 2026 08:39:42 -0700 Subject: [PATCH] M10: clean up empty mount directories after unmount Privileged unmount now does a best-effort rmdir on the mount point after umount succeeds. Only removes empty directories; non-empty dirs and errors are silently ignored. Co-Authored-By: Claude Opus 4.6 (1M context) --- internal/cryptsetup/cryptsetup.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/cryptsetup/cryptsetup.go b/internal/cryptsetup/cryptsetup.go index 13c1e6e..73621ca 100644 --- a/internal/cryptsetup/cryptsetup.go +++ b/internal/cryptsetup/cryptsetup.go @@ -64,7 +64,8 @@ func Mount(devicePath, mountpoint string) (string, error) { return mountpoint, nil } -// Unmount unmounts the given mountpoint using privileged umount. +// Unmount unmounts the given mountpoint using privileged umount, then +// removes the mount directory if it is empty. func Unmount(mountpoint string) error { args := withPrivilege([]string{"umount", mountpoint}) cmd := exec.Command(args[0], args[1:]...) @@ -73,6 +74,12 @@ func Unmount(mountpoint string) error { if err := cmd.Run(); err != nil { return fmt.Errorf("umount %s: %w", mountpoint, err) } + + // Clean up empty mount directory. Best-effort — ignore errors + // (directory may not be empty or may be a system path). + rmdirArgs := withPrivilege([]string{"rmdir", mountpoint}) + exec.Command(rmdirArgs[0], rmdirArgs[1:]...).Run() + return nil }