mirror of https://github.com/spf13/afero.git
MkdirAll first
This commit is contained in:
parent
03968e0515
commit
544ea15b3b
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue