feat(ftp-server): treat moving across file systems as copying (#7704 close #7701)

* feat(ftp-server): treat moving across file systems as copying

* fix: ensure compatibility across different fs on the same driver
pull/7673/head
KirCute_ECT 2024-12-25 21:12:30 +08:00 committed by GitHub
parent b72e85a73a
commit 40b0e66efe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package ftp
import (
"context"
"fmt"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
@ -64,8 +65,14 @@ func Rename(ctx context.Context, oldPath, newPath string) error {
if !user.CanFTPManage() || !user.CanMove() || (srcBase != dstBase && !user.CanRename()) {
return errs.PermissionDenied
}
if err := fs.Move(ctx, srcPath, dstDir); err != nil {
return err
if err = fs.Move(ctx, srcPath, dstDir); err != nil {
if srcBase != dstBase {
return err
}
if _, err1 := fs.Copy(ctx, srcPath, dstDir); err1 != nil {
return fmt.Errorf("failed move for %+v, and failed try copying for %+v", err, err1)
}
return nil
}
if srcBase != dstBase {
return fs.Rename(ctx, stdpath.Join(dstDir, srcBase), dstBase)