Skip to content

Commit

Permalink
normalise permission denied error as file not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Dec 8, 2020
1 parent 7230c61 commit f5fd2fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,8 @@ func normaliseError(err error) error {
return io.EOF
case sshFxNoSuchFile:
return os.ErrNotExist
case sshFxPermissionDenied:
return os.ErrPermission
case sshFxOk:
return nil
default:
Expand Down
9 changes: 3 additions & 6 deletions client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,13 @@ func TestClientCreateFailed(t *testing.T) {
defer sftp.Close()

f, err := ioutil.TempFile("", "sftptest-createfailed")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

defer f.Close()
defer os.Remove(f.Name())

f2, err := sftp.Create(f.Name())
if err1, ok := err.(*StatusError); !ok || err1.Code != sshFxPermissionDenied {
t.Fatalf("Create: want: %v, got %#v", sshFxPermissionDenied, err)
}
require.True(t, os.IsPermission(err))
if err == nil {
f2.Close()
}
Expand Down

0 comments on commit f5fd2fb

Please sign in to comment.