fix: clean up stale raw mounts before scanning in attach wizard
After an interrupted attach wizard, the raw mount stays behind, causing the device to appear as "mounted" in scan results. Now the scan button calls cancel first, which unmounts any stale raw mounts that have no bind mount in fstab. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -323,6 +323,54 @@ func CleanupRawMount(rawPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanupStaleRawMounts finds and removes raw mounts that have no corresponding
|
||||
// bind mount — i.e., leftovers from an interrupted attach wizard.
|
||||
// A raw mount is considered "in use" if fstab has a bind entry sourcing from it.
|
||||
func CleanupStaleRawMounts() {
|
||||
data, err := os.ReadFile("/proc/mounts")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Read fstab to check for bind mount entries
|
||||
fstabData, _ := os.ReadFile(FstabPath)
|
||||
fstabLines := strings.Split(string(fstabData), "\n")
|
||||
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < 2 {
|
||||
continue
|
||||
}
|
||||
mountPoint := fields[1]
|
||||
if !strings.HasPrefix(mountPoint, RawMountBase+"/") {
|
||||
continue
|
||||
}
|
||||
// Only consider direct children of RawMountBase (e.g., /mnt/.felhom-raw/hdd_1)
|
||||
rel := strings.TrimPrefix(mountPoint, RawMountBase+"/")
|
||||
if strings.Contains(rel, "/") {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if any fstab bind entry sources from this raw mount path
|
||||
inUse := false
|
||||
for _, fl := range fstabLines {
|
||||
fl = strings.TrimSpace(fl)
|
||||
if fl == "" || strings.HasPrefix(fl, "#") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(fl, "bind") && strings.HasPrefix(fl, mountPoint) {
|
||||
inUse = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !inUse {
|
||||
_ = exec.Command("umount", mountPoint).Run()
|
||||
_ = os.Remove(mountPoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
// getBlkidValue runs blkid to get a single value (TYPE, UUID, LABEL) for a device.
|
||||
|
||||
Reference in New Issue
Block a user