Skip to content

Commit d9eb188

Browse files
committed
feat: check parent dir before upload
1 parent 083395e commit d9eb188

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

internal/operations/fs.go

+17
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,22 @@ func Remove(ctx context.Context, account driver.Driver, path string) error {
130130
}
131131

132132
func Put(ctx context.Context, account driver.Driver, parentPath string, file model.FileStreamer) error {
133+
f, err := Get(ctx, account, parentPath)
134+
if err != nil {
135+
// if parent dir not exists, create it
136+
if driver.IsErrObjectNotFound(err) {
137+
err = MakeDir(ctx, account, parentPath)
138+
if err != nil {
139+
return errors.WithMessagef(err, "failed to make parent dir [%s]", parentPath)
140+
}
141+
} else {
142+
return errors.WithMessage(err, "failed to get parent dir")
143+
}
144+
} else {
145+
// object exists, check if it is a dir
146+
if !f.IsDir() {
147+
return errors.Errorf("object [%s] is not a dir", parentPath)
148+
}
149+
}
133150
return account.Put(ctx, parentPath, file)
134151
}

internal/task/task.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// manage task, such as file upload, file copy between accounts, offline download, etc.
22
package task
33

4-
import "context"
5-
64
type Task struct {
7-
Name string
8-
Func func(context.Context) error
9-
Status string
10-
Error error
11-
Finish bool
5+
Name string
6+
Status string
7+
Error error
8+
Finish bool
9+
Children []*Task
1210
}

0 commit comments

Comments
 (0)