feat: add copy to task manager

This commit is contained in:
Noah Hsu
2022-06-17 21:23:44 +08:00
parent 53e969e894
commit fa6e918fc7
10 changed files with 143 additions and 70 deletions

View File

@ -2,6 +2,7 @@ package operations
import (
"context"
log "github.com/sirupsen/logrus"
"sort"
"strings"
"time"
@ -85,8 +86,15 @@ func UpdateAccount(ctx context.Context, account model.Account) error {
return nil
}
// SaveDriverAccount call from specific driver
func SaveDriverAccount(driver driver.Driver) error {
// MustSaveDriverAccount call from specific driver
func MustSaveDriverAccount(driver driver.Driver) {
err := saveDriverAccount(driver)
if err != nil {
log.Errorf("failed save driver account: %s", err)
}
}
func saveDriverAccount(driver driver.Driver) error {
account := driver.GetAccount()
addition := driver.GetAddition()
bytes, err := utils.Json.Marshal(addition)

View File

@ -182,7 +182,7 @@ func Remove(ctx context.Context, account driver.Driver, path string) error {
return account.Remove(ctx, obj)
}
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, up driver.UpdateProgress) error {
err := MakeDir(ctx, account, parentPath)
if err != nil {
return errors.WithMessagef(err, "failed to make dir [%s]", parentPath)
@ -192,5 +192,9 @@ func Put(ctx context.Context, account driver.Driver, parentPath string, file mod
if err != nil {
return errors.WithMessagef(err, "failed to get dir [%s]", parentPath)
}
return account.Put(ctx, parentDir, file)
// if up is nil, set a default to prevent panic
if up == nil {
up = func(p float64) {}
}
return account.Put(ctx, parentDir, file, up)
}