Merge pull request #8531 from cardyok/bugfix_mount_path_symlink

bugfix: resolve symlink when looking up mountpoint
This commit is contained in:
Derek McGowan 2023-05-22 17:06:16 -07:00 committed by GitHub
commit ca5d6b6bad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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