Skip to content

Commit

Permalink
fix(ftp-server): work unproperly when base url is not root (#7693)
Browse files Browse the repository at this point in the history
* fix(ftp-server): work unproperly when base url is not root

* fix: avoid merge conflict
  • Loading branch information
KirCute authored Dec 25, 2024
1 parent bb2aec2 commit 6aaf597
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
14 changes: 10 additions & 4 deletions server/ftp/afero.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
ftpserver "github.com/KirCute/ftpserverlib-pasvportmap"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/spf13/afero"
"os"
"time"
Expand Down Expand Up @@ -91,7 +92,12 @@ func (a *AferoAdapter) GetHandle(name string, flags int, offset int64) (ftpserve
if (flags & os.O_APPEND) != 0 {
return nil, errs.NotSupport
}
_, err := fs.Get(a.ctx, name, &fs.GetArgs{})
user := a.ctx.Value("user").(*model.User)
path, err := user.JoinPath(name)
if err != nil {
return nil, err
}
_, err = fs.Get(a.ctx, path, &fs.GetArgs{})
exists := err == nil
if (flags&os.O_CREATE) == 0 && !exists {
return nil, errs.ObjectNotFound
Expand All @@ -102,12 +108,12 @@ func (a *AferoAdapter) GetHandle(name string, flags int, offset int64) (ftpserve
if (flags & os.O_WRONLY) != 0 {
trunc := (flags & os.O_TRUNC) != 0
if fileSize > 0 {
return OpenUploadWithLength(a.ctx, name, trunc, fileSize)
return OpenUploadWithLength(a.ctx, path, trunc, fileSize)
} else {
return OpenUpload(a.ctx, name, trunc)
return OpenUpload(a.ctx, path, trunc)
}
}
return OpenDownload(a.ctx, name)
return OpenDownload(a.ctx, path)
}

func (a *AferoAdapter) SetNextFileSize(size int64) {
Expand Down
6 changes: 1 addition & 5 deletions server/ftp/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ type FileDownloadProxy struct {
closers *utils.Closers
}

func OpenDownload(ctx context.Context, path string) (*FileDownloadProxy, error) {
func OpenDownload(ctx context.Context, reqPath string) (*FileDownloadProxy, error) {
user := ctx.Value("user").(*model.User)
reqPath, err := user.JoinPath(path)
if err != nil {
return nil, err
}
meta, err := op.GetNearestMeta(reqPath)
if err != nil {
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
Expand Down
4 changes: 0 additions & 4 deletions server/ftp/fsup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ type FileUploadProxy struct {

func uploadAuth(ctx context.Context, path string) error {
user := ctx.Value("user").(*model.User)
path, err := user.JoinPath(path)
if err != nil {
return err
}
meta, err := op.GetNearestMeta(stdpath.Dir(path))
if err != nil {
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
Expand Down

0 comments on commit 6aaf597

Please sign in to comment.