sftpd: remove workarounds for directory listing

The underlying issue was fixed in pkg/sftp 1.13.2
This commit is contained in:
Nicola Murino 2021-07-11 16:26:40 +02:00
parent bd5191dfc5
commit 7344366ce8
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
4 changed files with 4 additions and 55 deletions

View file

@ -65,5 +65,5 @@ func (fi *FileInfo) SetMode(mode os.FileMode) {
// Sys provides the underlying data source (can return nil) // Sys provides the underlying data source (can return nil)
func (fi *FileInfo) Sys() interface{} { func (fi *FileInfo) Sys() interface{} {
return fi.getFileInfoSys() return nil
} }

View file

@ -206,13 +206,7 @@ func (fs *SFTPFs) Stat(name string) (os.FileInfo, error) {
if err := fs.checkConnection(); err != nil { if err := fs.checkConnection(); err != nil {
return nil, err return nil, err
} }
info, err := fs.sftpClient.Stat(name) return fs.sftpClient.Stat(name)
if err != nil {
return nil, err
}
fi := NewFileInfo(info.Name(), info.IsDir(), info.Size(), info.ModTime(), false)
fi.SetMode(info.Mode())
return fi, nil
} }
// Lstat returns a FileInfo describing the named file // Lstat returns a FileInfo describing the named file
@ -220,13 +214,7 @@ func (fs *SFTPFs) Lstat(name string) (os.FileInfo, error) {
if err := fs.checkConnection(); err != nil { if err := fs.checkConnection(); err != nil {
return nil, err return nil, err
} }
info, err := fs.sftpClient.Lstat(name) return fs.sftpClient.Lstat(name)
if err != nil {
return nil, err
}
fi := NewFileInfo(info.Name(), info.IsDir(), info.Size(), info.ModTime(), false)
fi.SetMode(info.Mode())
return fi, nil
} }
// Open opens the named file for reading // Open opens the named file for reading
@ -407,18 +395,7 @@ func (fs *SFTPFs) ReadDir(dirname string) ([]os.FileInfo, error) {
if err := fs.checkConnection(); err != nil { if err := fs.checkConnection(); err != nil {
return nil, err return nil, err
} }
entries, err := fs.sftpClient.ReadDir(dirname) return fs.sftpClient.ReadDir(dirname)
if err != nil {
return nil, err
}
result := make([]os.FileInfo, 0, len(entries))
for _, entry := range entries {
info := NewFileInfo(entry.Name(), entry.IsDir(), entry.Size(), entry.ModTime(), false)
info.SetMode(entry.Mode())
result = append(result, info)
}
return result, nil
} }
// IsUploadResumeSupported returns true if resuming uploads is supported. // IsUploadResumeSupported returns true if resuming uploads is supported.

View file

@ -4,33 +4,10 @@ package vfs
import ( import (
"errors" "errors"
"os"
"syscall"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var (
defaultUID, defaultGID int
)
func init() {
defaultUID = os.Getuid()
defaultGID = os.Getuid()
if defaultUID < 0 {
defaultUID = 65534
}
if defaultGID < 0 {
defaultGID = 65534
}
}
func (fi FileInfo) getFileInfoSys() interface{} {
return &syscall.Stat_t{
Uid: uint32(defaultUID),
Gid: uint32(defaultGID)}
}
func isCrossDeviceError(err error) bool { func isCrossDeviceError(err error) bool {
return errors.Is(err, unix.EXDEV) return errors.Is(err, unix.EXDEV)
} }

View file

@ -2,15 +2,10 @@ package vfs
import ( import (
"errors" "errors"
"syscall"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
func (fi FileInfo) getFileInfoSys() interface{} {
return syscall.Win32FileAttributeData{}
}
func isCrossDeviceError(err error) bool { func isCrossDeviceError(err error) bool {
return errors.Is(err, windows.ERROR_NOT_SAME_DEVICE) return errors.Is(err, windows.ERROR_NOT_SAME_DEVICE)
} }