From 544ea15b3bd3dde8793868c2540e1339e708bf3b Mon Sep 17 00:00:00 2001 From: mkvolkov Date: Sun, 21 Aug 2022 09:07:08 +0300 Subject: [PATCH] MkdirAll first --- rclonefs/fs.go | 30 +++++++++++++++++++++++++++++- rclonetest/main.go | 4 ++-- 2 files changed, 31 insertions(+), 3 deletions(-) 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)