MkdirAll first

This commit is contained in:
mkvolkov 2022-08-21 09:07:08 +03:00
parent 03968e0515
commit 544ea15b3b
2 changed files with 31 additions and 3 deletions

View File

@ -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
}

View File

@ -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)