Skip to content

Commit

Permalink
feat(fs): add put return after finished
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 24, 2022
1 parent 956a5ae commit 3f49271
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 10 additions & 2 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ func Remove(ctx context.Context, path string) error {
return err
}

func Put(ctx context.Context, dstDirPath string, file model.FileStreamer) error {
err := put(ctx, dstDirPath, file)
func PutDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer) error {
err := putDirectly(ctx, dstDirPath, file)
if err != nil {
log.Errorf("failed put %s: %+v", dstDirPath, err)
}
return err
}

func PutAsTask(dstDirPath string, file model.FileStreamer) error {
err := putAsTask(dstDirPath, file)
if err != nil {
log.Errorf("failed put %s: %+v", dstDirPath, err)
}
Expand Down
16 changes: 14 additions & 2 deletions internal/fs/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var UploadTaskManager = task.NewTaskManager[uint64](3, func(tid *uint64) {
atomic.AddUint64(tid, 1)
})

// Put add as a put task
func put(ctx context.Context, dstDirPath string, file model.FileStreamer) error {
// putAsTask add as a put task and return immediately
func putAsTask(dstDirPath string, file model.FileStreamer) error {
account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
if account.Config().NoUpload {
return errors.WithStack(errs.UploadNotSupported)
Expand All @@ -32,3 +32,15 @@ func put(ctx context.Context, dstDirPath string, file model.FileStreamer) error
}))
return nil
}

// putDirect put the file and return after finish
func putDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer) error {
account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
if account.Config().NoUpload {
return errors.WithStack(errs.UploadNotSupported)
}
if err != nil {
return errors.WithMessage(err, "failed get account")
}
return operations.Put(ctx, account, dstDirActualPath, file, nil)
}

0 comments on commit 3f49271

Please sign in to comment.