bugfix: resolve symlink when looking up mountpoint

Signed-off-by: Cardy.Tang <zuniorone@gmail.com>
This commit is contained in:
Cardy.Tang 2023-05-18 21:35:33 +08:00
parent 878132923d
commit a6cd5e3f4f

View File

@ -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