mirror of https://github.com/Xhofe/alist
chore(fs): rename some param
parent
9633af4e25
commit
55c4a925ba
|
@ -21,47 +21,47 @@ var CopyTaskManager = task.NewTaskManager[uint64, struct{}](3, func(tid *uint64)
|
|||
|
||||
// Copy if in an account, call move method
|
||||
// if not, add copy task
|
||||
func Copy(ctx context.Context, account driver.Driver, srcPath, dstPath string) (bool, error) {
|
||||
srcAccount, srcActualPath, err := operations.GetAccountAndActualPath(srcPath)
|
||||
func Copy(ctx context.Context, account driver.Driver, srcObjPath, dstDirPath string) (bool, error) {
|
||||
srcAccount, srcObjActualPath, err := operations.GetAccountAndActualPath(srcObjPath)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "failed get src account")
|
||||
}
|
||||
dstAccount, dstActualPath, err := operations.GetAccountAndActualPath(dstPath)
|
||||
dstAccount, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "failed get dst account")
|
||||
}
|
||||
// copy if in an account, just call driver.Copy
|
||||
if srcAccount.GetAccount() == dstAccount.GetAccount() {
|
||||
return false, operations.Copy(ctx, account, srcActualPath, dstActualPath)
|
||||
return false, operations.Copy(ctx, account, srcObjActualPath, dstDirActualPath)
|
||||
}
|
||||
// not in an account
|
||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64, struct{}]{
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcActualPath, dstAccount.GetAccount().VirtualPath, dstActualPath),
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjActualPath, dstAccount.GetAccount().VirtualPath, dstDirActualPath),
|
||||
Func: func(task *task.Task[uint64, struct{}]) error {
|
||||
return CopyBetween2Accounts(task, srcAccount, dstAccount, srcActualPath, dstActualPath)
|
||||
return CopyBetween2Accounts(task, srcAccount, dstAccount, srcObjActualPath, dstDirActualPath)
|
||||
},
|
||||
}))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func CopyBetween2Accounts(t *task.Task[uint64, struct{}], srcAccount, dstAccount driver.Driver, srcPath, dstPath string) error {
|
||||
func CopyBetween2Accounts(t *task.Task[uint64, struct{}], srcAccount, dstAccount driver.Driver, srcObjPath, dstDirPath string) error {
|
||||
t.SetStatus("getting src object")
|
||||
srcObj, err := operations.Get(t.Ctx, srcAccount, srcPath)
|
||||
srcObj, err := operations.Get(t.Ctx, srcAccount, srcObjPath)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get src [%s] file", srcPath)
|
||||
return errors.WithMessagef(err, "failed get src [%s] file", srcObjPath)
|
||||
}
|
||||
if srcObj.IsDir() {
|
||||
t.SetStatus("src object is dir, listing objs")
|
||||
objs, err := operations.List(t.Ctx, srcAccount, srcPath)
|
||||
objs, err := operations.List(t.Ctx, srcAccount, srcObjPath)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed list src [%s] objs", srcPath)
|
||||
return errors.WithMessagef(err, "failed list src [%s] objs", srcObjPath)
|
||||
}
|
||||
for _, obj := range objs {
|
||||
if utils.IsCanceled(t.Ctx) {
|
||||
return nil
|
||||
}
|
||||
srcObjPath := stdpath.Join(srcPath, obj.GetName())
|
||||
dstObjPath := stdpath.Join(dstPath, obj.GetName())
|
||||
srcObjPath := stdpath.Join(srcObjPath, obj.GetName())
|
||||
dstObjPath := stdpath.Join(dstDirPath, obj.GetName())
|
||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64, struct{}]{
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjPath, dstAccount.GetAccount().VirtualPath, dstObjPath),
|
||||
Func: func(t *task.Task[uint64, struct{}]) error {
|
||||
|
@ -71,27 +71,27 @@ func CopyBetween2Accounts(t *task.Task[uint64, struct{}], srcAccount, dstAccount
|
|||
}
|
||||
} else {
|
||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64, struct{}]{
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcPath, dstAccount.GetAccount().VirtualPath, dstPath),
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjPath, dstAccount.GetAccount().VirtualPath, dstDirPath),
|
||||
Func: func(t *task.Task[uint64, struct{}]) error {
|
||||
return CopyFileBetween2Accounts(t, srcAccount, dstAccount, srcPath, dstPath)
|
||||
return CopyFileBetween2Accounts(t, srcAccount, dstAccount, srcObjPath, dstDirPath)
|
||||
},
|
||||
}))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CopyFileBetween2Accounts(tsk *task.Task[uint64, struct{}], srcAccount, dstAccount driver.Driver, srcPath, dstPath string) error {
|
||||
srcFile, err := operations.Get(tsk.Ctx, srcAccount, srcPath)
|
||||
func CopyFileBetween2Accounts(tsk *task.Task[uint64, struct{}], srcAccount, dstAccount driver.Driver, srcFilePath, dstDirPath string) error {
|
||||
srcFile, err := operations.Get(tsk.Ctx, srcAccount, srcFilePath)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get src [%s] file", srcPath)
|
||||
return errors.WithMessagef(err, "failed get src [%s] file", srcFilePath)
|
||||
}
|
||||
link, err := operations.Link(tsk.Ctx, srcAccount, srcPath, model.LinkArgs{})
|
||||
link, err := operations.Link(tsk.Ctx, srcAccount, srcFilePath, model.LinkArgs{})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get [%s] link", srcPath)
|
||||
return errors.WithMessagef(err, "failed get [%s] link", srcFilePath)
|
||||
}
|
||||
stream, err := getFileStreamFromLink(srcFile, link)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get [%s] stream", srcPath)
|
||||
return errors.WithMessagef(err, "failed get [%s] stream", srcFilePath)
|
||||
}
|
||||
return operations.Put(tsk.Ctx, dstAccount, dstPath, stream, tsk.SetProgress)
|
||||
return operations.Put(tsk.Ctx, dstAccount, dstDirPath, stream, tsk.SetProgress)
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ var UploadTaskManager = task.NewTaskManager[uint64, struct{}](3, func(tid *uint6
|
|||
})
|
||||
|
||||
// Put add as a put task
|
||||
func Put(ctx context.Context, account driver.Driver, dstDir string, file model.FileStreamer) error {
|
||||
account, actualParentPath, err := operations.GetAccountAndActualPath(dstDir)
|
||||
func Put(ctx context.Context, account driver.Driver, dstDirPath string, file model.FileStreamer) error {
|
||||
account, actualParentPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
if account.Config().NoUpload {
|
||||
return errors.WithStack(ErrUploadNotSupported)
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ func MakeDir(ctx context.Context, account driver.Driver, path string) error {
|
|||
return operations.MakeDir(ctx, account, actualPath)
|
||||
}
|
||||
|
||||
func Move(ctx context.Context, account driver.Driver, srcPath, dstPath string) error {
|
||||
func Move(ctx context.Context, account driver.Driver, srcPath, dstDirPath string) error {
|
||||
srcAccount, srcActualPath, err := operations.GetAccountAndActualPath(srcPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get src account")
|
||||
}
|
||||
dstAccount, dstActualPath, err := operations.GetAccountAndActualPath(dstPath)
|
||||
dstAccount, dstActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get dst account")
|
||||
}
|
||||
|
|
|
@ -145,12 +145,12 @@ func MakeDir(ctx context.Context, account driver.Driver, path string) error {
|
|||
}
|
||||
}
|
||||
|
||||
func Move(ctx context.Context, account driver.Driver, srcPath, dstPath string) error {
|
||||
func Move(ctx context.Context, account driver.Driver, srcPath, dstDirPath string) error {
|
||||
srcObj, err := Get(ctx, account, srcPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed to get src object")
|
||||
}
|
||||
dstDir, err := Get(ctx, account, stdpath.Dir(dstPath))
|
||||
dstDir, err := Get(ctx, account, dstDirPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed to get dst dir")
|
||||
}
|
||||
|
@ -166,12 +166,12 @@ func Rename(ctx context.Context, account driver.Driver, srcPath, dstName string)
|
|||
}
|
||||
|
||||
// Copy Just copy file[s] in an account
|
||||
func Copy(ctx context.Context, account driver.Driver, srcPath, dstPath string) error {
|
||||
func Copy(ctx context.Context, account driver.Driver, srcPath, dstDirPath string) error {
|
||||
srcObj, err := Get(ctx, account, srcPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed to get src object")
|
||||
}
|
||||
dstDir, err := Get(ctx, account, stdpath.Dir(dstPath))
|
||||
dstDir, err := Get(ctx, account, dstDirPath)
|
||||
return account.Copy(ctx, srcObj, dstDir)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue