Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 305 client write #310

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ type Client struct {
// already exists. If successful, methods on the returned File can be used for
// I/O; the associated file descriptor has mode O_RDWR. If you need more
// control over the flags/mode used to open the file see client.OpenFile.
//
// Note that some SFTP servers (eg. AWS Transfer) do not support opening files
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d probably recommend a paragraph break here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

// read/write at the same time. For those services you will need to use
// `client.OpenFile(os.O_WRONLY|os.O_CREATE|os.O_TRUNC)`.
func (c *Client) Create(path string) (*File, error) {
return c.open(path, flags(os.O_RDWR|os.O_CREATE|os.O_TRUNC))
}
Expand Down
9 changes: 8 additions & 1 deletion sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,11 @@ type StatusError struct {
msg, lang string
}

func (s *StatusError) Error() string { return fmt.Sprintf("sftp: %q (%v)", s.msg, fx(s.Code)) }
func (s *StatusError) Error() string {
return fmt.Sprintf("sftp: %q (%v)", s.msg, fx(s.Code))
}

// FxCode returns the error code typed to match against the exported codes
func (s *StatusError) FxCode() fxerr {
return fxerr(s.Code)
}
28 changes: 28 additions & 0 deletions sftp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sftp

import (
"io"
"syscall"
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

func TestErrFxCode(t *testing.T) {
ider := sshFxpStatusPacket{ID: 1}
table := []struct {
err error
fx fxerr
}{
{err: errors.New("random error"), fx: ErrSSHFxFailure},
{err: syscall.EBADF, fx: ErrSSHFxFailure},
{err: syscall.ENOENT, fx: ErrSSHFxNoSuchFile},
{err: syscall.EPERM, fx: ErrSSHFxPermissionDenied},
{err: io.EOF, fx: ErrSSHFxEOF},
}
for _, tt := range table {
statusErr := statusFromError(ider, tt.err).StatusError
assert.Equal(t, statusErr.FxCode(), tt.fx)
}
}