mirror of https://github.com/Xhofe/alist
feat: check parent dir before upload
parent
083395ee53
commit
d9eb188b7a
|
@ -130,5 +130,22 @@ func Remove(ctx context.Context, account driver.Driver, path string) error {
|
|||
}
|
||||
|
||||
func Put(ctx context.Context, account driver.Driver, parentPath string, file model.FileStreamer) error {
|
||||
f, err := Get(ctx, account, parentPath)
|
||||
if err != nil {
|
||||
// if parent dir not exists, create it
|
||||
if driver.IsErrObjectNotFound(err) {
|
||||
err = MakeDir(ctx, account, parentPath)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed to make parent dir [%s]", parentPath)
|
||||
}
|
||||
} else {
|
||||
return errors.WithMessage(err, "failed to get parent dir")
|
||||
}
|
||||
} else {
|
||||
// object exists, check if it is a dir
|
||||
if !f.IsDir() {
|
||||
return errors.Errorf("object [%s] is not a dir", parentPath)
|
||||
}
|
||||
}
|
||||
return account.Put(ctx, parentPath, file)
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
// manage task, such as file upload, file copy between accounts, offline download, etc.
|
||||
package task
|
||||
|
||||
import "context"
|
||||
|
||||
type Task struct {
|
||||
Name string
|
||||
Func func(context.Context) error
|
||||
Status string
|
||||
Error error
|
||||
Finish bool
|
||||
Name string
|
||||
Status string
|
||||
Error error
|
||||
Finish bool
|
||||
Children []*Task
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue