Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

local: fix mkdir error when trying to copy files to the root of a drive on windows

Nick Craig-Woodd49ba652e2e1
diff --git a/backend/local/local.go b/backend/local/local.go
index 1be99a144..26ae8ede1 100644
--- a/backend/local/local.go
+++ b/backend/local/local.go
@@ -151,7 +151,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
}
if err == nil && fi.Mode().IsRegular() {
// It is a file, so use the parent as the root
- f.root, _ = getDirFile(f.root)
+ f.root = filepath.Dir(f.root)
// return an error with an fs which points to the parent
return f, fs.ErrorIsFile
}
@@ -565,7 +565,7 @@ func (f *Fs) DirMove(src fs.Fs, srcRemote, dstRemote string) error {
}
// Create parent of destination
- dstParentPath, _ := getDirFile(dstPath)
+ dstParentPath := filepath.Dir(dstPath)
err = os.MkdirAll(dstParentPath, 0777)
if err != nil {
return err
@@ -784,7 +784,7 @@ func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
// mkdirAll makes all the directories needed to store the object
func (o *Object) mkdirAll() error {
- dir, _ := getDirFile(o.path)
+ dir := filepath.Dir(o.path)
return os.MkdirAll(dir, 0777)
}
@@ -872,17 +872,6 @@ func (o *Object) Remove() error {
return remove(o.path)
}
-// Return the directory and file from an OS path. Assumes
-// os.PathSeparator is used.
-func getDirFile(s string) (string, string) {
- i := strings.LastIndex(s, string(os.PathSeparator))
- dir, file := s[:i], s[i+1:]
- if dir == "" {
- dir = string(os.PathSeparator)
- }
- return dir, file
-}
-
// cleanPathFragment cleans an OS path fragment which is part of a
// bigger path and not necessarily absolute
func cleanPathFragment(s string) string {