diff --git a/rclonefs/fs.go b/rclonefs/fs.go index 2662f79..efeef12 100644 --- a/rclonefs/fs.go +++ b/rclonefs/fs.go @@ -76,7 +76,35 @@ func (rcfs *RCFS) Mkdir(name string, perm os.FileMode) error { } func (rcfs *RCFS) MkdirAll(name string, perm os.FileMode) error { - // TODO + name = rcfs.AbsPath(name) + name = strings.Trim(name, "/") + + var ( + front string = "/" + current string + back string + ok bool + ) + + for { + current, back, ok = strings.Cut(name, "/") + if !ok { + front = front + name + if e := rcfs.Fs.Mkdir(front, perm); e != nil && !os.IsExist(e) { + return e + } + break + } + + front = front + current + "/" + + if e := rcfs.Fs.Mkdir(front, perm); e != nil && !os.IsExist(e) { + return e + } + + name = back + } + return nil } diff --git a/rclonetest/main.go b/rclonetest/main.go index decca6f..09890b3 100644 --- a/rclonetest/main.go +++ b/rclonetest/main.go @@ -8,9 +8,9 @@ import ( ) func main() { - RFS, _ := rclonefs.CreateRCFS("pcloud_mv1:/cfg") + RFS, _ := rclonefs.CreateRCFS("pcloud_mv1:") - err := RFS.RemoveAll("yml") + err := RFS.MkdirAll("/data/passwords/sites/github/", 0750) if err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1)