1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-20 02:03:17 +00:00

vendor: update all dependencies

This commit is contained in:
Nick Craig-Wood
2018-03-19 15:51:38 +00:00
parent 940df88eb2
commit d64789528d
4309 changed files with 1327278 additions and 1001118 deletions

View File

@@ -1,6 +1,7 @@
package sftp
import (
"context"
"encoding"
"io"
"path"
@@ -14,8 +15,6 @@ import (
var maxTxPacket uint32 = 1 << 15
type handleHandler func(string) string
// Handlers contains the 4 SFTP server request handlers.
type Handlers struct {
FileGet FileReader
@@ -82,7 +81,8 @@ func (rs *RequestServer) getRequest(handle, method string) (*Request, bool) {
if !ok || r.Method == method { // re-check needed b/c lock race
return r, ok
}
r = &Request{Method: method, Filepath: r.Filepath, state: r.state}
r = r.copy()
r.Method = method
rs.openRequests[handle] = r
return r, ok
}
@@ -102,12 +102,14 @@ func (rs *RequestServer) Close() error { return rs.conn.Close() }
// Serve requests for user session
func (rs *RequestServer) Serve() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
runWorker := func(ch requestChan) {
wg.Add(1)
go func() {
defer wg.Done()
if err := rs.packetWorker(ch); err != nil {
if err := rs.packetWorker(ctx, ch); err != nil {
rs.conn.Close() // shuts down recvPacket
}
}()
@@ -137,10 +139,19 @@ func (rs *RequestServer) Serve() error {
close(pktChan) // shuts down sftpServerWorkers
wg.Wait() // wait for all workers to exit
// make sure all open requests are properly closed
// (eg. possible on dropped connections, client crashes, etc.)
for handle, req := range rs.openRequests {
delete(rs.openRequests, handle)
req.close()
}
return err
}
func (rs *RequestServer) packetWorker(pktChan chan requestPacket) error {
func (rs *RequestServer) packetWorker(
ctx context.Context, pktChan chan requestPacket,
) error {
for pkt := range pktChan {
var rpkt responsePacket
switch pkt := pkt.(type) {
@@ -152,15 +163,15 @@ func (rs *RequestServer) packetWorker(pktChan chan requestPacket) error {
case *sshFxpRealpathPacket:
rpkt = cleanPacketPath(pkt)
case *sshFxpOpendirPacket:
request := requestFromPacket(pkt)
request := requestFromPacket(ctx, pkt)
handle := rs.nextRequest(request)
rpkt = sshFxpHandlePacket{pkt.id(), handle}
case *sshFxpOpenPacket:
request := requestFromPacket(pkt)
request := requestFromPacket(ctx, pkt)
handle := rs.nextRequest(request)
rpkt = sshFxpHandlePacket{pkt.id(), handle}
if pkt.hasPflags(ssh_FXF_CREAT) {
if p := request.call(rs.Handlers, pkt); !isOk(p) {
if p := request.call(rs.Handlers, pkt); !statusOk(p) {
rpkt = p // if error in write, return it
}
}
@@ -173,8 +184,9 @@ func (rs *RequestServer) packetWorker(pktChan chan requestPacket) error {
rpkt = request.call(rs.Handlers, pkt)
}
case hasPath:
request := requestFromPacket(pkt)
request := requestFromPacket(ctx, pkt)
rpkt = request.call(rs.Handlers, pkt)
request.close()
default:
return errors.Errorf("unexpected packet type %T", pkt)
}
@@ -188,7 +200,7 @@ func (rs *RequestServer) packetWorker(pktChan chan requestPacket) error {
}
// True is responsePacket is an OK status packet
func isOk(rpkt responsePacket) bool {
func statusOk(rpkt responsePacket) bool {
p, ok := rpkt.(sshFxpStatusPacket)
return ok && p.StatusError.Code == ssh_FX_OK
}
@@ -224,7 +236,3 @@ func (rs *RequestServer) sendPacket(m encoding.BinaryMarshaler) error {
}
return nil
}
func (rs *RequestServer) sendError(p ider, err error) error {
return rs.sendPacket(statusFromError(p, err))
}