Prefer friendly paths for get-local-path
This commit is contained in:
@@ -134,10 +134,46 @@ func runGetLocalPathCommand(args []string, cfg config, password string) error {
|
||||
if len(matches) == 0 {
|
||||
return fmt.Errorf("entry %s not found under mounted by-id tree", id)
|
||||
}
|
||||
fmt.Println(matches[0])
|
||||
path := matches[0]
|
||||
if friendlyPath, err := friendlyLocalPath(mountPoint, path); err == nil && friendlyPath != "" {
|
||||
path = friendlyPath
|
||||
}
|
||||
fmt.Println(path)
|
||||
return nil
|
||||
}
|
||||
|
||||
func friendlyLocalPath(mountPoint, byIDPath string) (string, error) {
|
||||
byIDInfo, err := os.Stat(byIDPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
byIDRoot := filepath.Join(mountPoint, "by-id")
|
||||
var found string
|
||||
err = filepath.Walk(mountPoint, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil || info == nil {
|
||||
return nil
|
||||
}
|
||||
if path == byIDRoot || strings.HasPrefix(path, byIDRoot+string(os.PathSeparator)) {
|
||||
if info.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if os.SameFile(byIDInfo, info) {
|
||||
found = path
|
||||
return filepath.SkipAll
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return found, nil
|
||||
}
|
||||
|
||||
func runGetURLCommand(args []string, cfg config, password string) error {
|
||||
flags := flag.NewFlagSet("get-url", flag.ExitOnError)
|
||||
if err := flags.Parse(args); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user