From 3f49271db61787d7aa312a7406e5a69c1507d767 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Fri, 24 Jun 2022 14:21:28 +0800 Subject: [PATCH] feat(fs): add put return after finished --- internal/fs/fs.go | 12 ++++++++++-- internal/fs/put.go | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 7d98115f..2f53f079 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -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) } diff --git a/internal/fs/put.go b/internal/fs/put.go index 5ffae600..413a9e98 100644 --- a/internal/fs/put.go +++ b/internal/fs/put.go @@ -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) @@ -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) +}