fix: copy task name

refactor/fs
Noah Hsu 2022-06-17 21:30:16 +08:00
parent fa6e918fc7
commit b9f9e5853e
2 changed files with 10 additions and 11 deletions

View File

@ -22,23 +22,23 @@ func CopyBetween2Accounts(ctx context.Context, srcAccount, dstAccount driver.Dri
return errors.WithMessagef(err, "failed get src [%s] file", srcPath) return errors.WithMessagef(err, "failed get src [%s] file", srcPath)
} }
if srcObj.IsDir() { if srcObj.IsDir() {
setStatus("src object is dir, listing files") setStatus("src object is dir, listing objs")
files, err := operations.List(ctx, srcAccount, srcPath) objs, err := operations.List(ctx, srcAccount, srcPath)
if err != nil { if err != nil {
return errors.WithMessagef(err, "failed list src [%s] files", srcPath) return errors.WithMessagef(err, "failed list src [%s] objs", srcPath)
} }
for _, file := range files { for _, obj := range objs {
if utils.IsCanceled(ctx) { if utils.IsCanceled(ctx) {
return nil return nil
} }
srcFilePath := stdpath.Join(srcPath, file.GetName()) srcObjPath := stdpath.Join(srcPath, obj.GetName())
dstFilePath := stdpath.Join(dstPath, file.GetName()) dstObjPath := stdpath.Join(dstPath, obj.GetName())
copyTaskManager.Add(fmt.Sprintf("copy %s to %s", srcFilePath, dstFilePath), func(task *task.Task) error { copyTaskManager.Add(fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjPath, dstAccount.GetAccount().VirtualPath, dstObjPath), func(task *task.Task) error {
return CopyBetween2Accounts(ctx, srcAccount, dstAccount, srcFilePath, dstFilePath, task.SetStatus) return CopyBetween2Accounts(ctx, srcAccount, dstAccount, srcObjPath, dstObjPath, task.SetStatus)
}) })
} }
} else { } else {
copyTaskManager.Add(fmt.Sprintf("copy %s to %s", srcPath, dstPath), func(task *task.Task) error { copyTaskManager.Add(fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcPath, dstAccount.GetAccount().VirtualPath, dstPath), func(task *task.Task) error {
return CopyFileBetween2Accounts(task.Ctx, srcAccount, dstAccount, srcPath, dstPath, func(percentage float64) { return CopyFileBetween2Accounts(task.Ctx, srcAccount, dstAccount, srcPath, dstPath, func(percentage float64) {
task.SetStatus(fmt.Sprintf("uploading: %2.f%", percentage)) task.SetStatus(fmt.Sprintf("uploading: %2.f%", percentage))
}) })

View File

@ -57,8 +57,7 @@ func Copy(ctx context.Context, account driver.Driver, srcPath, dstPath string) (
return false, operations.Copy(ctx, account, srcActualPath, dstActualPath) return false, operations.Copy(ctx, account, srcActualPath, dstActualPath)
} }
// not in an account // not in an account
// TODO add status set callback to put copyTaskManager.Add(fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcActualPath, dstAccount.GetAccount().VirtualPath, dstActualPath), func(task *task.Task) error {
copyTaskManager.Add(fmt.Sprintf("copy %s to %s", srcActualPath, dstActualPath), func(task *task.Task) error {
return CopyBetween2Accounts(task.Ctx, srcAccount, dstAccount, srcActualPath, dstActualPath, task.SetStatus) return CopyBetween2Accounts(task.Ctx, srcAccount, dstAccount, srcActualPath, dstActualPath, task.SetStatus)
}) })
return true, nil return true, nil