mirror of
https://github.com/rclone/rclone.git
synced 2024-12-25 16:38:59 +01:00
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
This commit is contained in:
parent
a12c94caff
commit
2437eb3cce
@ -376,7 +376,7 @@ func rename(osOldPath, osNewPath string) error {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("Failed to stat destination: %s: %w", osNewPath, err)
|
||||
}
|
||||
parent := vfscommon.OsFindParent(osNewPath)
|
||||
parent := vfscommon.OSFindParent(osNewPath)
|
||||
err = createDir(parent)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create parent dir: %s: %w", parent, err)
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// OsFindParent returns the parent directory of name, or "" for the
|
||||
// OSFindParent returns the parent directory of name, or "" for the
|
||||
// root for OS native paths.
|
||||
func OsFindParent(name string) string {
|
||||
func OSFindParent(name string) string {
|
||||
parent := filepath.Dir(name)
|
||||
if parent == "." || parent == "/" {
|
||||
if parent == "." || (len(parent) == 1 && parent[0] == filepath.Separator) {
|
||||
parent = ""
|
||||
}
|
||||
return parent
|
||||
|
Loading…
Reference in New Issue
Block a user