From a6cd5e3f4f83988c46f0a1963b6d4eae039f2710 Mon Sep 17 00:00:00 2001 From: "Cardy.Tang" Date: Thu, 18 May 2023 21:35:33 +0800 Subject: [PATCH] bugfix: resolve symlink when looking up mountpoint Signed-off-by: Cardy.Tang --- mount/lookup_unix.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mount/lookup_unix.go b/mount/lookup_unix.go index 6fb16f6dd..6755c0b22 100644 --- a/mount/lookup_unix.go +++ b/mount/lookup_unix.go @@ -29,12 +29,17 @@ import ( func Lookup(dir string) (Info, error) { dir = filepath.Clean(dir) - m, err := mountinfo.GetMounts(mountinfo.ParentsFilter(dir)) + resolvedDir, err := filepath.EvalSymlinks(dir) if err != nil { - return Info{}, fmt.Errorf("failed to find the mount info for %q: %w", dir, err) + return Info{}, fmt.Errorf("failed to resolve symlink for %q: %w", dir, err) + } + + m, err := mountinfo.GetMounts(mountinfo.ParentsFilter(resolvedDir)) + if err != nil { + return Info{}, fmt.Errorf("failed to find the mount info for %q: %w", resolvedDir, err) } if len(m) == 0 { - return Info{}, fmt.Errorf("failed to find the mount info for %q", dir) + return Info{}, fmt.Errorf("failed to find the mount info for %q", resolvedDir) } // find the longest matching mount point