sftpfs: map path resolution error to permission denied

This commit is contained in:
Nicola Murino 2021-10-16 10:52:19 +02:00
parent 27b5f1bf59
commit ca464b5ffc
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB

View file

@ -455,6 +455,9 @@ func (*SFTPFs) IsNotExist(err error) bool {
// IsPermission returns a boolean indicating whether the error is known to // IsPermission returns a boolean indicating whether the error is known to
// report that permission is denied. // report that permission is denied.
func (*SFTPFs) IsPermission(err error) bool { func (*SFTPFs) IsPermission(err error) bool {
if _, ok := err.(*pathResolutionError); ok {
return true
}
return os.IsPermission(err) return os.IsPermission(err)
} }
@ -612,11 +615,11 @@ func (fs *SFTPFs) isSubDir(name string) error {
} }
if len(name) < len(fs.config.Prefix) { if len(name) < len(fs.config.Prefix) {
err := fmt.Errorf("path %#v is not inside: %#v", name, fs.config.Prefix) err := fmt.Errorf("path %#v is not inside: %#v", name, fs.config.Prefix)
return err return &pathResolutionError{err: err.Error()}
} }
if !strings.HasPrefix(name, fs.config.Prefix+"/") { if !strings.HasPrefix(name, fs.config.Prefix+"/") {
err := fmt.Errorf("path %#v is not inside: %#v", name, fs.config.Prefix) err := fmt.Errorf("path %#v is not inside: %#v", name, fs.config.Prefix)
return err return &pathResolutionError{err: err.Error()}
} }
return nil return nil
} }