mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
don't open files when stating directory (#797)
This commit is contained in:
parent
e281cebb56
commit
31414a7536
@ -629,7 +629,7 @@ func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error {
|
|||||||
// on error just returns ""
|
// on error just returns ""
|
||||||
// does not return "application/octet-stream" as this is considered a detection failure
|
// does not return "application/octet-stream" as this is considered a detection failure
|
||||||
// can pass an existing fileInfo to avoid re-statting the file
|
// can pass an existing fileInfo to avoid re-statting the file
|
||||||
func DetectMimeType(path string, fileInfo fs.FileInfo) string {
|
func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string {
|
||||||
if fileInfo == nil {
|
if fileInfo == nil {
|
||||||
statRtn, err := os.Stat(path)
|
statRtn, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -657,6 +657,9 @@ func DetectMimeType(path string, fileInfo fs.FileInfo) string {
|
|||||||
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
|
if mimeType := mime.TypeByExtension(ext); mimeType != "" {
|
||||||
return mimeType
|
return mimeType
|
||||||
}
|
}
|
||||||
|
if !extended {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
fd, err := os.Open(path)
|
fd, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
|
@ -104,7 +104,7 @@ func (impl *ServerImpl) remoteStreamFileDir(ctx context.Context, path string, by
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt)
|
innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false)
|
||||||
fileInfoArr = append(fileInfoArr, innerFileInfo)
|
fileInfoArr = append(fileInfoArr, innerFileInfo)
|
||||||
if len(fileInfoArr) >= DirChunkSize {
|
if len(fileInfoArr) >= DirChunkSize {
|
||||||
dataCallback(fileInfoArr, nil)
|
dataCallback(fileInfoArr, nil)
|
||||||
@ -200,8 +200,8 @@ func (impl *ServerImpl) RemoteStreamFileCommand(ctx context.Context, data wshrpc
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func statToFileInfo(fullPath string, finfo fs.FileInfo) *wshrpc.FileInfo {
|
func statToFileInfo(fullPath string, finfo fs.FileInfo, extended bool) *wshrpc.FileInfo {
|
||||||
mimeType := utilfn.DetectMimeType(fullPath, finfo)
|
mimeType := utilfn.DetectMimeType(fullPath, finfo, extended)
|
||||||
rtn := &wshrpc.FileInfo{
|
rtn := &wshrpc.FileInfo{
|
||||||
Path: wavebase.ReplaceHomeDir(fullPath),
|
Path: wavebase.ReplaceHomeDir(fullPath),
|
||||||
Dir: computeDirPart(fullPath, finfo.IsDir()),
|
Dir: computeDirPart(fullPath, finfo.IsDir()),
|
||||||
@ -272,7 +272,7 @@ func (*ServerImpl) fileInfoInternal(path string, extended bool) (*wshrpc.FileInf
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot stat file %q: %w", path, err)
|
return nil, fmt.Errorf("cannot stat file %q: %w", path, err)
|
||||||
}
|
}
|
||||||
rtn := statToFileInfo(cleanedPath, finfo)
|
rtn := statToFileInfo(cleanedPath, finfo, extended)
|
||||||
if extended {
|
if extended {
|
||||||
rtn.ReadOnly = checkIsReadOnly(cleanedPath, finfo, true)
|
rtn.ReadOnly = checkIsReadOnly(cleanedPath, finfo, true)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user