mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 15:38:57 +01:00
2437eb3cce
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
27 lines
562 B
Go
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
|
|
}
|