Skip to content

Commit

Permalink
feat: check parent dir before upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 15, 2022
1 parent 083395e commit d9eb188
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 17 additions & 0 deletions internal/operations/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
12 changes: 5 additions & 7 deletions internal/task/task.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d9eb188

Please sign in to comment.