feat: check parent dir before upload
This commit is contained in:
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 {
|
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)
|
return account.Put(ctx, parentPath, file)
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
// manage task, such as file upload, file copy between accounts, offline download, etc.
|
// manage task, such as file upload, file copy between accounts, offline download, etc.
|
||||||
package task
|
package task
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Name string
|
Name string
|
||||||
Func func(context.Context) error
|
|
||||||
Status string
|
Status string
|
||||||
Error error
|
Error error
|
||||||
Finish bool
|
Finish bool
|
||||||
|
Children []*Task
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user