From ac0ea56f988c7af4fb499eb16b43f08b54bcfddb Mon Sep 17 00:00:00 2001 From: James Coleman Date: Mon, 30 Mar 2026 22:43:53 -0500 Subject: [PATCH] Fix isMounted to resolve symlinks and normalize paths The target path may contain symlinks (e.g. /media/Storage/ -> /mnt/merged/raid/Storage/) but /proc/mounts records the resolved real path. Use filepath.EvalSymlinks and filepath.Clean so the comparison matches regardless of symlinks or trailing slashes. --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index cfcfe53..87558aa 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/exec" + "path/filepath" "regexp" "strings" "sync" @@ -34,7 +35,14 @@ type App struct { var app *App // isMounted checks /proc/mounts for a target mountpoint to determine if it is mounted. +// Symlinks in the target path are resolved so the comparison matches the real +// paths recorded by the kernel. func isMounted(target string) bool { + cleanTarget := filepath.Clean(target) + if resolved, err := filepath.EvalSymlinks(cleanTarget); err == nil { + cleanTarget = resolved + } + file, err := os.Open("/proc/mounts") if err != nil { log.Fatal(err) @@ -47,7 +55,7 @@ func isMounted(target string) bool { if len(args) < 3 { continue } - if args[1] == target { + if filepath.Clean(args[1]) == cleanTarget { return true } }