Skip to content

Commit

Permalink
perf: update get file
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Jan 8, 2025
1 parent 6057656 commit 53809ff
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions pkg/httpd/sftpvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,30 +226,15 @@ func (u *UserVolume) Parents(path string, dep int) []elfinder.FileDir {
func (u *UserVolume) GetFile(path string) (fileData elfinder.FileData, err error) {
logger.Debug("GetFile path: ", path)
var rest elfinder.FileData
sfStatus, err := u.UserSftp.Stat(filepath.Join(u.basePath, TrimPrefix(path)))
if err != nil {
logger.Errorf("Get File path %s stat failed: %s", path, err)
return rest, err
}

sf, err := u.UserSftp.Open(filepath.Join(u.basePath, TrimPrefix(path)))
if err != nil {
return rest, err
}
go func() {
sf1, err := u.UserSftp.Open(filepath.Join(u.basePath, TrimPrefix(path)))
if err != nil {
logger.Errorf("Record file %s err: %s", path, err)
return
}
if err1 := u.recorder.ChunkedRecord(sf.FTPLog, sf1, 0, sfStatus.Size()); err1 != nil {
logger.Errorf("Record file err: %s", err1)
}
}()

// _, _ = sf.Seek(0, io.SeekStart)
// 屏蔽 sftp*File 的 WriteTo 方法,防止调用 sftp stat 命令
fileData = elfinder.FileData{Reader: &fileReader{read: sf}, Size: sfStatus.Size()}
fileData = elfinder.FileData{Reader: &fileReader{read: sf}, Size: 0}
return fileData, nil
}

Expand Down

0 comments on commit 53809ff

Please sign in to comment.