mirror of
https://github.com/rclone/rclone.git
synced 2024-11-28 19:34:55 +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) {
|
if !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("Failed to stat destination: %s: %w", osNewPath, err)
|
return fmt.Errorf("Failed to stat destination: %s: %w", osNewPath, err)
|
||||||
}
|
}
|
||||||
parent := vfscommon.OsFindParent(osNewPath)
|
parent := vfscommon.OSFindParent(osNewPath)
|
||||||
err = createDir(parent)
|
err = createDir(parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create parent dir: %s: %w", parent, err)
|
return fmt.Errorf("Failed to create parent dir: %s: %w", parent, err)
|
||||||
|
@ -5,11 +5,11 @@ import (
|
|||||||
"path/filepath"
|
"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.
|
// root for OS native paths.
|
||||||
func OsFindParent(name string) string {
|
func OSFindParent(name string) string {
|
||||||
parent := filepath.Dir(name)
|
parent := filepath.Dir(name)
|
||||||
if parent == "." || parent == "/" {
|
if parent == "." || (len(parent) == 1 && parent[0] == filepath.Separator) {
|
||||||
parent = ""
|
parent = ""
|
||||||
}
|
}
|
||||||
return parent
|
return parent
|
||||||
|
Loading…
Reference in New Issue
Block a user