Fix #195 Handler wrappers deal with errors

TLDR; have the Handler wrappers generate the response packets for the
errors instead of returning the errors.

Errors from the handers was returned up the stack to the request-server
handler call. In cases of errors the packet for the error was then
generated using the passed in packet (the incoming packet).

For file read/write/list operations the incoming packet data (includeing
ID) is put in a queue/channel so that it can be handled by the same file
handling code returned by the handler.

Due to gorouting scheduling, in some cases the packets in the channel
won't line up with the incoming packets. That is the worker that took an
incoming packet with one ID might respond with a packet with a different
ID. This doesn't matter as the reply order of packets doesn't matter.

BUT when this response packet that doesn't match IDs with the incoming
packet system returns an error, it uses the incoming packets ID to
generate the error packet. So the error response would use that ID and
the packet from the queue, once processed, would also use that ID
(because on success  it uses the ID from the packet in the queue).

This patch fixes the issue by having the code that works with the
packets, either incoming or from the queue, generate the error packet.
So there is no chance of them getting out of sync.
3 files changed
tree: 5884d96dd5dbc9fe9f5f32fca9f13599141a3012
  1. examples/
  2. server_standalone/
  3. .gitignore
  4. .travis.yml
  5. attrs.go
  6. attrs_stubs.go
  7. attrs_test.go
  8. attrs_unix.go
  9. client.go
  10. client_integration_darwin_test.go
  11. client_integration_linux_test.go
  12. client_integration_test.go
  13. client_test.go
  14. conn.go
  15. CONTRIBUTORS
  16. debug.go
  17. example_test.go
  18. LICENSE
  19. match.go
  20. other_test.go
  21. packet-manager.go
  22. packet-manager_go1.8.go
  23. packet-manager_legacy.go
  24. packet-manager_test.go
  25. packet-typing.go
  26. packet.go
  27. packet_test.go
  28. README.md
  29. release.go
  30. request-example.go
  31. request-interfaces.go
  32. request-readme.md
  33. request-server.go
  34. request-server_test.go
  35. request-unix.go
  36. request.go
  37. request_test.go
  38. request_windows.go
  39. server.go
  40. server_integration_test.go
  41. server_statvfs_darwin.go
  42. server_statvfs_impl.go
  43. server_statvfs_linux.go
  44. server_statvfs_stubs.go
  45. server_stubs.go
  46. server_test.go
  47. server_unix.go
  48. sftp.go
README.md

sftp

The sftp package provides support for file system operations on remote ssh servers using the SFTP subsystem. It also implements an SFTP server for serving files from the filesystem.

UNIX Build Status GoDoc

usage and examples

See godoc.org/github.com/pkg/sftp for examples and usage.

The basic operation of the package mirrors the facilities of the os package.

The Walker interface for directory traversal is heavily inspired by Keith Rarick's fs package.

roadmap

  • There is way too much duplication in the Client methods. If there was an unmarshal(interface{}) method this would reduce a heap of the duplication.

contributing

We welcome pull requests, bug fixes and issue reports.

Before proposing a large change, first please discuss your change by raising an issue.

For API/code bugs, please include a small, self contained code example to reproduce the issue. For pull requests, remember test coverage.

We try to handle issues and pull requests with a 0 open philosophy. That means we will try to address the submission as soon as possible and will work toward a resolution. If progress can no longer be made (eg. unreproducible bug) or stops (eg. unresponsive submitter), we will close the bug.

Thanks.