Skip to content

Commit

Permalink
perf: 优化支持 WinSCP 的目录文件下载
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Mar 25, 2024
1 parent a4d7421 commit 4ff3139
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/handler/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func (s *SftpHandler) Fileread(r *sftp.Request) (io.ReaderAt, error) {
s.recorder.FinishFTPFile(f.FTPLog.ID)

}()
return f, err
// 包裹一层,兼容 WinSCP 目录的批量下载
return NewReaderAt(f), err
}

func (s *SftpHandler) Close() {
Expand All @@ -142,6 +143,10 @@ func NewWriterAt(f *srvconn.SftpFile, recorder *proxy.FTPFileRecorder) io.Writer
return &clientReadWritAt{f: f, mu: new(sync.RWMutex), recorder: recorder}
}

func NewReaderAt(f *srvconn.SftpFile) io.ReaderAt {
return &clientReadWritAt{f: f, mu: new(sync.RWMutex)}
}

type clientReadWritAt struct {
f *srvconn.SftpFile
mu *sync.RWMutex
Expand All @@ -159,6 +164,12 @@ func (c *clientReadWritAt) WriteAt(p []byte, off int64) (n int, err error) {
return c.f.Write(p)
}

func (c *clientReadWritAt) ReadAt(p []byte, off int64) (n int, err error) {
c.mu.Lock()
defer c.mu.Unlock()
return c.f.ReadAt(p, off)
}

type wrapperSFTPFileInfo struct {
f os.FileInfo
}
Expand Down

0 comments on commit 4ff3139

Please sign in to comment.