sftpfs: Implement OpenFile method

Before, the OpenFile method was unimplemented, and just returned `nil,
nil`. Because the Afero.TempFile method calls the OpenFile method, this
behavior caused a nil pointer exception when TempFile was used with
sftpfs.

This commit adds a simple implementation for sftpfs.OpenFile, fixing the
exception thrown when using it with TempFile.
This commit is contained in:
Kevin Lin 2018-03-18 19:03:56 -07:00
parent bbf41cb36d
commit 887ec81f2f
1 changed files with 7 additions and 1 deletions

View File

@ -94,8 +94,14 @@ func (s Fs) Open(name string) (afero.File, error) {
return FileOpen(s.client, name) return FileOpen(s.client, name)
} }
// OpenFile calls the OpenFile method on the SSHFS connection. The mode argument
// is ignored because it's ignored by the github.com/pkg/sftp implementation.
func (s Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) { func (s Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
return nil, nil sshfsFile, err := s.client.OpenFile(name, flag)
if err != nil {
return nil, err
}
return &File{fd: sshfsFile}, nil
} }
func (s Fs) Remove(name string) error { func (s Fs) Remove(name string) error {