Skip to content

Commit

Permalink
Merge pull request pkg#1 from pkg/master
Browse files Browse the repository at this point in the history
Update from pkg/sftp
  • Loading branch information
vansante authored Dec 20, 2017
2 parents 97614f0 + 1d5374a commit c2bca6d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: go
go_import_path: github.com/pkg/sftp

# current and previous stable releases, and tip
# current and previous stable releases, plus tip
# remember to exclude previous and tip for macs below
go:
- 1.7.x
- 1.8.x
- 1.9.x
- tip

os:
Expand All @@ -14,7 +15,7 @@ os:
matrix:
exclude:
- os: osx
go: 1.7.x
go: 1.8.x
- os: osx
go: tip

Expand Down
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
)

// InternalInconsistency indicates the packets sent and the data queued to be
// written to the file don't match up. It is an unusual error and if you get it
// you should file a ticket.
// written to the file don't match up. It is an unusual error and usually is
// caused by bad behavior server side or connection issues. The error is
// limited in scope to the call where it happened, the client object is still
// OK to use as long as the connection is still open.
var InternalInconsistency = errors.New("internal inconsistency")

// A ClientOption is a function which applies configuration to a Client.
Expand Down
8 changes: 4 additions & 4 deletions request-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ func (rs *RequestServer) getRequest(handle string) (*Request, bool) {
return &r, ok
}

func (rs *RequestServer) closeRequest(handle string) {
func (rs *RequestServer) closeRequest(handle string) error {
rs.openRequestLock.Lock()
defer rs.openRequestLock.Unlock()
if r, ok := rs.openRequests[handle]; ok {
r.close()
delete(rs.openRequests, handle)
return r.close()
}
return syscall.EBADF
}

// Close the read/write/closer to trigger exiting the main server loop
Expand Down Expand Up @@ -129,8 +130,7 @@ func (rs *RequestServer) packetWorker(pktChan chan requestPacket) error {
rpkt = sshFxVersionPacket{sftpProtocolVersion, nil}
case *sshFxpClosePacket:
handle := pkt.getHandle()
rs.closeRequest(handle)
rpkt = statusFromError(pkt, nil)
rpkt = statusFromError(pkt, rs.closeRequest(handle))
case *sshFxpRealpathPacket:
rpkt = cleanPacketPath(pkt)
case isOpener:
Expand Down
7 changes: 4 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,16 @@ func (r *Request) getLister() ListerAt {
}

// Close reader/writer if possible
func (r *Request) close() {
func (r *Request) close() error {
rd := r.getReader()
if c, ok := rd.(io.Closer); ok {
c.Close()
return c.Close()
}
wt := r.getWriter()
if c, ok := wt.(io.Closer); ok {
c.Close()
return c.Close()
}
return nil
}

// called from worker to handle packet/request
Expand Down
2 changes: 1 addition & 1 deletion sftp.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package sftp implements the SSH File Transfer Protocol as described in
// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt
// https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
package sftp

import (
Expand Down

0 comments on commit c2bca6d

Please sign in to comment.