feat: get abs before get mount point

This commit is contained in:
Samuel N Cui
2024-03-18 21:39:12 +08:00
parent b13b740940
commit af05f05ce1

6
fs.go
View File

@@ -2,6 +2,7 @@ package acp
import (
"fmt"
"path/filepath"
"strings"
mapset "github.com/deckarep/golang-set/v2"
@@ -33,6 +34,11 @@ func getMountpointCache() (func(string) string, error) {
mps := mountPoints.ToSlice()
return Cache(func(path string) string {
path, err := filepath.Abs(path)
if err != nil {
panic(fmt.Errorf("get abs from file path failed, path= '%s', %w", path, err))
}
for _, mp := range mps {
if strings.HasPrefix(path, mp) {
return mp