fix(ftp): dead lock on Read
(close #5128)
This commit is contained in:
parent
cb8867fcc1
commit
34fadecc2c
@ -48,10 +48,9 @@ func NewFTPFileReader(conn *ftp.ServerConn, path string) *FTPFileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *FTPFileReader) Read(buf []byte) (n int, err error) {
|
func (r *FTPFileReader) Read(buf []byte) (n int, err error) {
|
||||||
|
n, err = r.ReadAt(buf, r.offset)
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
n, err = r.ReadAt(buf, r.offset)
|
|
||||||
r.offset += int64(n)
|
r.offset += int64(n)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,21 @@ package common
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/internal/net"
|
"github.com/alist-org/alist/v3/internal/net"
|
||||||
"github.com/alist-org/alist/v3/pkg/http_range"
|
"github.com/alist-org/alist/v3/pkg/http_range"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error {
|
func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error {
|
||||||
if link.MFile != nil {
|
if link.MFile != nil {
|
||||||
|
defer link.MFile.Close()
|
||||||
attachFileName(w, file)
|
attachFileName(w, file)
|
||||||
http.ServeContent(w, r, file.GetName(), file.ModTime(), link.MFile)
|
http.ServeContent(w, r, file.GetName(), file.ModTime(), link.MFile)
|
||||||
defer link.MFile.Close()
|
|
||||||
return nil
|
return nil
|
||||||
} else if link.RangeReadCloser != nil {
|
} else if link.RangeReadCloser != nil {
|
||||||
attachFileName(w, file)
|
attachFileName(w, file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user