mirror of https://github.com/Xhofe/alist
feat: recursive create folder
parent
2d60dab13c
commit
083395ee53
|
@ -1,11 +1,18 @@
|
||||||
package driver
|
package driver
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
pkgerr "github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrorDirNotFound = errors.New("directory not found")
|
|
||||||
ErrorObjectNotFound = errors.New("object not found")
|
ErrorObjectNotFound = errors.New("object not found")
|
||||||
ErrNotImplement = errors.New("not implement")
|
ErrNotImplement = errors.New("not implement")
|
||||||
ErrNotSupport = errors.New("not support")
|
ErrNotSupport = errors.New("not support")
|
||||||
ErrRelativePath = errors.New("access using relative path is not allowed")
|
ErrRelativePath = errors.New("access using relative path is not allowed")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func IsErrObjectNotFound(err error) bool {
|
||||||
|
return pkgerr.Cause(err) == ErrorObjectNotFound
|
||||||
|
}
|
||||||
|
|
|
@ -96,6 +96,19 @@ func Link(ctx context.Context, account driver.Driver, path string, args model.Li
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeDir(ctx context.Context, account driver.Driver, path string) error {
|
func MakeDir(ctx context.Context, account driver.Driver, path string) error {
|
||||||
|
// check if dir exists
|
||||||
|
f, err := Get(ctx, account, path)
|
||||||
|
if f != nil && f.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil && !driver.IsErrObjectNotFound(err) {
|
||||||
|
return errors.WithMessage(err, "failed to check if dir exists")
|
||||||
|
}
|
||||||
|
parentPath := stdpath.Dir(path)
|
||||||
|
err = MakeDir(ctx, account, parentPath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessagef(err, "failed to make parent dir [%s]", parentPath)
|
||||||
|
}
|
||||||
return account.MakeDir(ctx, path)
|
return account.MakeDir(ctx, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue