From ea096db8e4fac0a197a58cd3517b0d52fe736553 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sat, 23 Jan 2021 10:32:15 +0100 Subject: [PATCH] sftpfs: set the correct file mode --- templates/connections.html | 2 +- templates/message.html | 4 ++-- templates/status.html | 3 +-- vfs/fileinfo.go | 21 +++++++++++++-------- vfs/gcsfs.go | 4 ++-- vfs/s3fs.go | 4 ++-- vfs/sftpfs.go | 18 +++++++++++++----- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/templates/connections.html b/templates/connections.html index 4bc235f9..e393c7e1 100644 --- a/templates/connections.html +++ b/templates/connections.html @@ -44,7 +44,7 @@ {{else}} -
+
No user connected
{{end}} diff --git a/templates/message.html b/templates/message.html index ff23c6e5..dbde338a 100644 --- a/templates/message.html +++ b/templates/message.html @@ -11,13 +11,13 @@
{{if .Error}} -
+
{{.Error}}
{{end}} {{if .Success}} -
+
{{.Success}}
{{end}} diff --git a/templates/status.html b/templates/status.html index 1999fc81..d59f9fa4 100644 --- a/templates/status.html +++ b/templates/status.html @@ -88,8 +88,7 @@
-
+
Data provider

diff --git a/vfs/fileinfo.go b/vfs/fileinfo.go index 57b6531e..2493f808 100644 --- a/vfs/fileinfo.go +++ b/vfs/fileinfo.go @@ -15,7 +15,7 @@ type FileInfo struct { } // NewFileInfo creates file info. -func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time.Time, fullName bool) FileInfo { +func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time.Time, fullName bool) *FileInfo { mode := os.FileMode(0644) if isDirectory { mode = os.FileMode(0755) | os.ModeDir @@ -25,7 +25,7 @@ func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time. name = path.Base(name) } - return FileInfo{ + return &FileInfo{ name: name, sizeInBytes: sizeInBytes, modTime: modTime, @@ -34,31 +34,36 @@ func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time. } // Name provides the base name of the file. -func (fi FileInfo) Name() string { +func (fi *FileInfo) Name() string { return fi.name } // Size provides the length in bytes for a file. -func (fi FileInfo) Size() int64 { +func (fi *FileInfo) Size() int64 { return fi.sizeInBytes } // Mode provides the file mode bits -func (fi FileInfo) Mode() os.FileMode { +func (fi *FileInfo) Mode() os.FileMode { return fi.mode } // ModTime provides the last modification time. -func (fi FileInfo) ModTime() time.Time { +func (fi *FileInfo) ModTime() time.Time { return fi.modTime } // IsDir provides the abbreviation for Mode().IsDir() -func (fi FileInfo) IsDir() bool { +func (fi *FileInfo) IsDir() bool { return fi.mode&os.ModeDir != 0 } +// SetMode sets the file mode +func (fi *FileInfo) SetMode(mode os.FileMode) { + fi.mode = mode +} + // Sys provides the underlying data source (can return nil) -func (fi FileInfo) Sys() interface{} { +func (fi *FileInfo) Sys() interface{} { return fi.getFileInfoSys() } diff --git a/vfs/gcsfs.go b/vfs/gcsfs.go index 98399419..9ddbd551 100644 --- a/vfs/gcsfs.go +++ b/vfs/gcsfs.go @@ -102,7 +102,7 @@ func (fs *GCSFs) ConnectionID() string { // Stat returns a FileInfo describing the named file func (fs *GCSFs) Stat(name string) (os.FileInfo, error) { - var result FileInfo + var result *FileInfo var err error if name == "" || name == "." { err := fs.checkIfBucketExists() @@ -136,7 +136,7 @@ func (fs *GCSFs) Stat(name string) (os.FileInfo, error) { } func (fs *GCSFs) getStatCompat(name string) (os.FileInfo, error) { - var result FileInfo + var result *FileInfo attrs, err := fs.headObject(name + "/") if err != nil { return result, err diff --git a/vfs/s3fs.go b/vfs/s3fs.go index 56714513..e4cfeccd 100644 --- a/vfs/s3fs.go +++ b/vfs/s3fs.go @@ -108,7 +108,7 @@ func (fs *S3Fs) ConnectionID() string { // Stat returns a FileInfo describing the named file func (fs *S3Fs) Stat(name string) (os.FileInfo, error) { - var result FileInfo + var result *FileInfo if name == "/" || name == "." { err := fs.checkIfBucketExists() if err != nil { @@ -144,7 +144,7 @@ func (fs *S3Fs) Stat(name string) (os.FileInfo, error) { } func (fs *S3Fs) getStatForDir(name string) (os.FileInfo, error) { - var result FileInfo + var result *FileInfo obj, err := fs.headObject(name + "/") if err != nil { return result, err diff --git a/vfs/sftpfs.go b/vfs/sftpfs.go index 08e04c42..8879ca8c 100644 --- a/vfs/sftpfs.go +++ b/vfs/sftpfs.go @@ -151,7 +151,9 @@ func (fs *SFTPFs) Stat(name string) (os.FileInfo, error) { if err != nil { return nil, err } - return NewFileInfo(info.Name(), info.IsDir(), info.Size(), info.ModTime(), false), nil + 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 @@ -163,7 +165,9 @@ func (fs *SFTPFs) Lstat(name string) (os.FileInfo, error) { if err != nil { return nil, err } - return NewFileInfo(info.Name(), info.IsDir(), info.Size(), info.ModTime(), false), nil + 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 @@ -272,10 +276,14 @@ func (fs *SFTPFs) ReadDir(dirname string) ([]os.FileInfo, error) { if err != nil { return nil, err } - for idx, entry := range entries { - entries[idx] = NewFileInfo(entry.Name(), entry.IsDir(), entry.Size(), entry.ModTime(), false) + 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 entries, nil + return result, nil } // IsUploadResumeSupported returns true if upload resume is supported.