mirror of https://github.com/Xhofe/alist
fix(ftp-server): work unproperly when base url is not root (#7693)
* fix(ftp-server): work unproperly when base url is not root * fix: avoid merge conflictpull/7673/head
parent
bb2aec20e4
commit
6aaf5975c6
|
@ -6,6 +6,7 @@ import (
|
||||||
ftpserver "github.com/KirCute/ftpserverlib-pasvportmap"
|
ftpserver "github.com/KirCute/ftpserverlib-pasvportmap"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
"github.com/alist-org/alist/v3/internal/fs"
|
"github.com/alist-org/alist/v3/internal/fs"
|
||||||
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
@ -91,7 +92,12 @@ func (a *AferoAdapter) GetHandle(name string, flags int, offset int64) (ftpserve
|
||||||
if (flags & os.O_APPEND) != 0 {
|
if (flags & os.O_APPEND) != 0 {
|
||||||
return nil, errs.NotSupport
|
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
|
exists := err == nil
|
||||||
if (flags&os.O_CREATE) == 0 && !exists {
|
if (flags&os.O_CREATE) == 0 && !exists {
|
||||||
return nil, errs.ObjectNotFound
|
return nil, errs.ObjectNotFound
|
||||||
|
@ -102,12 +108,12 @@ func (a *AferoAdapter) GetHandle(name string, flags int, offset int64) (ftpserve
|
||||||
if (flags & os.O_WRONLY) != 0 {
|
if (flags & os.O_WRONLY) != 0 {
|
||||||
trunc := (flags & os.O_TRUNC) != 0
|
trunc := (flags & os.O_TRUNC) != 0
|
||||||
if fileSize > 0 {
|
if fileSize > 0 {
|
||||||
return OpenUploadWithLength(a.ctx, name, trunc, fileSize)
|
return OpenUploadWithLength(a.ctx, path, trunc, fileSize)
|
||||||
} else {
|
} 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) {
|
func (a *AferoAdapter) SetNextFileSize(size int64) {
|
||||||
|
|
|
@ -25,12 +25,8 @@ type FileDownloadProxy struct {
|
||||||
closers *utils.Closers
|
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)
|
user := ctx.Value("user").(*model.User)
|
||||||
reqPath, err := user.JoinPath(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
meta, err := op.GetNearestMeta(reqPath)
|
meta, err := op.GetNearestMeta(reqPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
||||||
|
|
|
@ -29,10 +29,6 @@ type FileUploadProxy struct {
|
||||||
|
|
||||||
func uploadAuth(ctx context.Context, path string) error {
|
func uploadAuth(ctx context.Context, path string) error {
|
||||||
user := ctx.Value("user").(*model.User)
|
user := ctx.Value("user").(*model.User)
|
||||||
path, err := user.JoinPath(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
meta, err := op.GetNearestMeta(stdpath.Dir(path))
|
meta, err := op.GetNearestMeta(stdpath.Dir(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
||||||
|
|
Loading…
Reference in New Issue