vendor: update all dependencies

This commit is contained in:
Nick Craig-Wood 2018-06-17 17:59:12 +01:00
parent 3f0789e2db
commit 08021c4636
2474 changed files with 435818 additions and 282709 deletions

106
vendor/github.com/pkg/sftp/client.go generated vendored
View file

@ -7,6 +7,7 @@ import (
"os"
"path"
"sync/atomic"
"syscall"
"time"
"github.com/kr/fs"
@ -75,6 +76,19 @@ func MaxPacket(size int) ClientOption {
return MaxPacketChecked(size)
}
// MaxConcurrentRequestsPerFile sets the maximum concurrent requests allowed for a single file.
//
// The default maximum concurrent requests is 64.
func MaxConcurrentRequestsPerFile(n int) ClientOption {
return func(c *Client) error {
if n < 1 {
return errors.Errorf("n must be greater or equal to 1")
}
c.maxConcurrentRequests = n
return nil
}
}
// NewClient creates a new SFTP client on conn, using zero or more option
// functions.
func NewClient(conn *ssh.Client, opts ...ClientOption) (*Client, error) {
@ -109,7 +123,8 @@ func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...ClientOption) (*Clie
},
inflight: make(map[uint32]chan<- result),
},
maxPacket: 1 << 15,
maxPacket: 1 << 15,
maxConcurrentRequests: 64,
}
if err := sftp.applyOptions(opts...); err != nil {
wr.Close()
@ -136,8 +151,9 @@ func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...ClientOption) (*Clie
type Client struct {
clientConn
maxPacket int // max packet size read or written.
nextid uint32
maxPacket int // max packet size read or written.
nextid uint32
maxConcurrentRequests int
}
// Create creates the named file mode 0666 (before umask), truncating it if it
@ -680,6 +696,54 @@ func (c *Client) Mkdir(path string) error {
}
}
// MkdirAll creates a directory named path, along with any necessary parents,
// and returns nil, or else returns an error.
// If path is already a directory, MkdirAll does nothing and returns nil.
// If path contains a regular file, an error is returned
func (c *Client) MkdirAll(path string) error {
// Most of this code mimics https://golang.org/src/os/path.go?s=514:561#L13
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
dir, err := c.Stat(path)
if err == nil {
if dir.IsDir() {
return nil
}
return &os.PathError{Op: "mkdir", Path: path, Err: syscall.ENOTDIR}
}
// Slow path: make sure parent exists and then call Mkdir for path.
i := len(path)
for i > 0 && os.IsPathSeparator(path[i-1]) { // Skip trailing path separator.
i--
}
j := i
for j > 0 && !os.IsPathSeparator(path[j-1]) { // Scan backward over element.
j--
}
if j > 1 {
// Create parent
err = c.MkdirAll(path[0 : j-1])
if err != nil {
return err
}
}
// Parent now exists; invoke Mkdir and use its result.
err = c.Mkdir(path)
if err != nil {
// Handle arguments like "foo/." by
// double-checking that directory doesn't exist.
dir, err1 := c.Lstat(path)
if err1 == nil && dir.IsDir() {
return nil
}
return err
}
return nil
}
// applyOptions applies options functions to the Client.
// If an error is encountered, option processing ceases.
func (c *Client) applyOptions(opts ...ClientOption) error {
@ -710,12 +774,15 @@ func (f *File) Name() string {
return f.path
}
const maxConcurrentRequests = 64
// Read reads up to len(b) bytes from the File. It returns the number of bytes
// read and an error, if any. Read follows io.Reader semantics, so when Read
// encounters an error or EOF condition after successfully reading n > 0 bytes,
// it returns the number of bytes read.
//
// To maximise throughput for transferring the entire file (especially
// over high latency links) it is recommended to use WriteTo rather
// than calling Read multiple times. io.Copy will do this
// automatically.
func (f *File) Read(b []byte) (int, error) {
// Split the read into multiple maxPacket sized concurrent reads
// bounded by maxConcurrentRequests. This allows reads with a suitably
@ -726,7 +793,7 @@ func (f *File) Read(b []byte) (int, error) {
offset := f.offset
// maxConcurrentRequests buffer to deal with broadcastErr() floods
// also must have a buffer of max value of (desiredInFlight - inFlight)
ch := make(chan result, maxConcurrentRequests+1)
ch := make(chan result, f.c.maxConcurrentRequests+1)
type inflightRead struct {
b []byte
offset uint64
@ -791,7 +858,7 @@ func (f *File) Read(b []byte) (int, error) {
if n < len(req.b) {
sendReq(req.b[l:], req.offset+uint64(l))
}
if desiredInFlight < maxConcurrentRequests {
if desiredInFlight < f.c.maxConcurrentRequests {
desiredInFlight++
}
default:
@ -811,6 +878,10 @@ func (f *File) Read(b []byte) (int, error) {
// WriteTo writes the file to w. The return value is the number of bytes
// written. Any error encountered during the write is also returned.
//
// This method is preferred over calling Read multiple times to
// maximise throughput for transferring the entire file (especially
// over high latency links).
func (f *File) WriteTo(w io.Writer) (int64, error) {
fi, err := f.Stat()
if err != nil {
@ -822,7 +893,7 @@ func (f *File) WriteTo(w io.Writer) (int64, error) {
writeOffset := offset
fileSize := uint64(fi.Size())
// see comment on same line in Read() above
ch := make(chan result, maxConcurrentRequests+1)
ch := make(chan result, f.c.maxConcurrentRequests+1)
type inflightRead struct {
b []byte
offset uint64
@ -902,7 +973,7 @@ func (f *File) WriteTo(w io.Writer) (int64, error) {
switch {
case offset > fileSize:
desiredInFlight = 1
case desiredInFlight < maxConcurrentRequests:
case desiredInFlight < f.c.maxConcurrentRequests:
desiredInFlight++
}
writeOffset += uint64(nbytes)
@ -956,6 +1027,11 @@ func (f *File) Stat() (os.FileInfo, error) {
// Write writes len(b) bytes to the File. It returns the number of bytes
// written and an error, if any. Write returns a non-nil error when n !=
// len(b).
//
// To maximise throughput for transferring the entire file (especially
// over high latency links) it is recommended to use ReadFrom rather
// than calling Write multiple times. io.Copy will do this
// automatically.
func (f *File) Write(b []byte) (int, error) {
// Split the write into multiple maxPacket sized concurrent writes
// bounded by maxConcurrentRequests. This allows writes with a suitably
@ -965,7 +1041,7 @@ func (f *File) Write(b []byte) (int, error) {
desiredInFlight := 1
offset := f.offset
// see comment on same line in Read() above
ch := make(chan result, maxConcurrentRequests+1)
ch := make(chan result, f.c.maxConcurrentRequests+1)
var firstErr error
written := len(b)
for len(b) > 0 || inFlight > 0 {
@ -1001,7 +1077,7 @@ func (f *File) Write(b []byte) (int, error) {
firstErr = err
break
}
if desiredInFlight < maxConcurrentRequests {
if desiredInFlight < f.c.maxConcurrentRequests {
desiredInFlight++
}
default:
@ -1021,12 +1097,16 @@ func (f *File) Write(b []byte) (int, error) {
// ReadFrom reads data from r until EOF and writes it to the file. The return
// value is the number of bytes read. Any error except io.EOF encountered
// during the read is also returned.
//
// This method is preferred over calling Write multiple times to
// maximise throughput for transferring the entire file (especially
// over high latency links).
func (f *File) ReadFrom(r io.Reader) (int64, error) {
inFlight := 0
desiredInFlight := 1
offset := f.offset
// see comment on same line in Read() above
ch := make(chan result, maxConcurrentRequests+1)
ch := make(chan result, f.c.maxConcurrentRequests+1)
var firstErr error
read := int64(0)
b := make([]byte, f.c.maxPacket)
@ -1065,7 +1145,7 @@ func (f *File) ReadFrom(r io.Reader) (int64, error) {
firstErr = err
break
}
if desiredInFlight < maxConcurrentRequests {
if desiredInFlight < f.c.maxConcurrentRequests {
desiredInFlight++
}
default: