From 7344366ce82833b86e0d678f6c895f2aead91bf4 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sun, 11 Jul 2021 16:26:40 +0200 Subject: [PATCH] sftpd: remove workarounds for directory listing The underlying issue was fixed in pkg/sftp 1.13.2 --- vfs/fileinfo.go | 2 +- vfs/sftpfs.go | 29 +++-------------------------- vfs/sys_unix.go | 23 ----------------------- vfs/sys_windows.go | 5 ----- 4 files changed, 4 insertions(+), 55 deletions(-) diff --git a/vfs/fileinfo.go b/vfs/fileinfo.go index 2493f808..bc90fce5 100644 --- a/vfs/fileinfo.go +++ b/vfs/fileinfo.go @@ -65,5 +65,5 @@ func (fi *FileInfo) SetMode(mode os.FileMode) { // Sys provides the underlying data source (can return nil) func (fi *FileInfo) Sys() interface{} { - return fi.getFileInfoSys() + return nil } diff --git a/vfs/sftpfs.go b/vfs/sftpfs.go index 54a7cd61..2b58bccb 100644 --- a/vfs/sftpfs.go +++ b/vfs/sftpfs.go @@ -206,13 +206,7 @@ func (fs *SFTPFs) Stat(name string) (os.FileInfo, error) { if err := fs.checkConnection(); err != nil { return nil, err } - info, err := 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 + return fs.sftpClient.Stat(name) } // 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 { return nil, err } - info, err := 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 + return fs.sftpClient.Lstat(name) } // 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 { return nil, err } - entries, err := 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 + return fs.sftpClient.ReadDir(dirname) } // IsUploadResumeSupported returns true if resuming uploads is supported. diff --git a/vfs/sys_unix.go b/vfs/sys_unix.go index 6c98f0f0..7b44f1cc 100644 --- a/vfs/sys_unix.go +++ b/vfs/sys_unix.go @@ -4,33 +4,10 @@ package vfs import ( "errors" - "os" - "syscall" "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 { return errors.Is(err, unix.EXDEV) } diff --git a/vfs/sys_windows.go b/vfs/sys_windows.go index 0521a2e8..e3ae1142 100644 --- a/vfs/sys_windows.go +++ b/vfs/sys_windows.go @@ -2,15 +2,10 @@ package vfs import ( "errors" - "syscall" "golang.org/x/sys/windows" ) -func (fi FileInfo) getFileInfoSys() interface{} { - return syscall.Win32FileAttributeData{} -} - func isCrossDeviceError(err error) bool { return errors.Is(err, windows.ERROR_NOT_SAME_DEVICE) }