1
mirror of https://github.com/rclone/rclone synced 2024-12-18 07:45:55 +01:00
rclone/vfs/vfscommon/path.go
albertony 2437eb3cce vfs: fix incorrect detection of root in parent directory utility function
When using filepath.Dir, a difference to path.Dir is that it returns os PathSeparator
instead of slash when the path consists entirely of separators.

Also fixed casing of the function name, use OS in all caps instead of Os
as recommended here: https://github.com/golang/go/wiki/CodeReviewComments#initialisms
2022-05-16 12:43:43 +02:00

27 lines
562 B
Go

package vfscommon
import (
"path"
"path/filepath"
)
// OSFindParent returns the parent directory of name, or "" for the
// root for OS native paths.
func OSFindParent(name string) string {
parent := filepath.Dir(name)
if parent == "." || (len(parent) == 1 && parent[0] == filepath.Separator) {
parent = ""
}
return parent
}
// FindParent returns the parent directory of name, or "" for the root
// for rclone paths.
func FindParent(name string) string {
parent := path.Dir(name)
if parent == "." || parent == "/" {
parent = ""
}
return parent
}