mirror of https://github.com/pkg/sftp.git
fix lint issues
These lint issues remain: - request-errors.go, aliases for new error types - request-attrs.go, UidGid. Changing this will break compatibility
This commit is contained in:
parent
43a60a90f4
commit
b4ea0fd6f6
36
attrs.go
36
attrs.go
|
@ -10,11 +10,11 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
ssh_FILEXFER_ATTR_SIZE = 0x00000001
|
||||
ssh_FILEXFER_ATTR_UIDGID = 0x00000002
|
||||
ssh_FILEXFER_ATTR_PERMISSIONS = 0x00000004
|
||||
ssh_FILEXFER_ATTR_ACMODTIME = 0x00000008
|
||||
ssh_FILEXFER_ATTR_EXTENDED = 0x80000000
|
||||
sshFileXferAttrSize = 0x00000001
|
||||
sshFileXferAttrUIDGID = 0x00000002
|
||||
sshFileXferAttrPermissions = 0x00000004
|
||||
sshFileXferAttrACmodTime = 0x00000008
|
||||
sshFileXferAttrExtented = 0x80000000
|
||||
)
|
||||
|
||||
// fileInfo is an artificial type designed to satisfy os.FileInfo.
|
||||
|
@ -77,9 +77,9 @@ func fileInfoFromStat(st *FileStat, name string) os.FileInfo {
|
|||
func fileStatFromInfo(fi os.FileInfo) (uint32, FileStat) {
|
||||
mtime := fi.ModTime().Unix()
|
||||
atime := mtime
|
||||
var flags uint32 = ssh_FILEXFER_ATTR_SIZE |
|
||||
ssh_FILEXFER_ATTR_PERMISSIONS |
|
||||
ssh_FILEXFER_ATTR_ACMODTIME
|
||||
var flags uint32 = sshFileXferAttrSize |
|
||||
sshFileXferAttrPermissions |
|
||||
sshFileXferAttrACmodTime
|
||||
|
||||
fileStat := FileStat{
|
||||
Size: uint64(fi.Size()),
|
||||
|
@ -101,23 +101,23 @@ func unmarshalAttrs(b []byte) (*FileStat, []byte) {
|
|||
|
||||
func getFileStat(flags uint32, b []byte) (*FileStat, []byte) {
|
||||
var fs FileStat
|
||||
if flags&ssh_FILEXFER_ATTR_SIZE == ssh_FILEXFER_ATTR_SIZE {
|
||||
if flags&sshFileXferAttrSize == sshFileXferAttrSize {
|
||||
fs.Size, b = unmarshalUint64(b)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_UIDGID == ssh_FILEXFER_ATTR_UIDGID {
|
||||
if flags&sshFileXferAttrUIDGID == sshFileXferAttrUIDGID {
|
||||
fs.UID, b = unmarshalUint32(b)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_UIDGID == ssh_FILEXFER_ATTR_UIDGID {
|
||||
if flags&sshFileXferAttrUIDGID == sshFileXferAttrUIDGID {
|
||||
fs.GID, b = unmarshalUint32(b)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_PERMISSIONS == ssh_FILEXFER_ATTR_PERMISSIONS {
|
||||
if flags&sshFileXferAttrPermissions == sshFileXferAttrPermissions {
|
||||
fs.Mode, b = unmarshalUint32(b)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_ACMODTIME == ssh_FILEXFER_ATTR_ACMODTIME {
|
||||
if flags&sshFileXferAttrACmodTime == sshFileXferAttrACmodTime {
|
||||
fs.Atime, b = unmarshalUint32(b)
|
||||
fs.Mtime, b = unmarshalUint32(b)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_EXTENDED == ssh_FILEXFER_ATTR_EXTENDED {
|
||||
if flags&sshFileXferAttrExtented == sshFileXferAttrExtented {
|
||||
var count uint32
|
||||
count, b = unmarshalUint32(b)
|
||||
ext := make([]StatExtended, count)
|
||||
|
@ -152,17 +152,17 @@ func marshalFileInfo(b []byte, fi os.FileInfo) []byte {
|
|||
flags, fileStat := fileStatFromInfo(fi)
|
||||
|
||||
b = marshalUint32(b, flags)
|
||||
if flags&ssh_FILEXFER_ATTR_SIZE != 0 {
|
||||
if flags&sshFileXferAttrSize != 0 {
|
||||
b = marshalUint64(b, fileStat.Size)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_UIDGID != 0 {
|
||||
if flags&sshFileXferAttrUIDGID != 0 {
|
||||
b = marshalUint32(b, fileStat.UID)
|
||||
b = marshalUint32(b, fileStat.GID)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_PERMISSIONS != 0 {
|
||||
if flags&sshFileXferAttrPermissions != 0 {
|
||||
b = marshalUint32(b, fileStat.Mode)
|
||||
}
|
||||
if flags&ssh_FILEXFER_ATTR_ACMODTIME != 0 {
|
||||
if flags&sshFileXferAttrACmodTime != 0 {
|
||||
b = marshalUint32(b, fileStat.Atime)
|
||||
b = marshalUint32(b, fileStat.Mtime)
|
||||
}
|
||||
|
|
|
@ -20,17 +20,17 @@ var unmarshalAttrsTests = []struct {
|
|||
{marshal(nil, struct {
|
||||
Flags uint32
|
||||
Size uint64
|
||||
}{ssh_FILEXFER_ATTR_SIZE, 20}), &fileInfo{size: 20, mtime: time.Unix(int64(0), 0)}, nil},
|
||||
}{sshFileXferAttrSize, 20}), &fileInfo{size: 20, mtime: time.Unix(int64(0), 0)}, nil},
|
||||
{marshal(nil, struct {
|
||||
Flags uint32
|
||||
Size uint64
|
||||
Permissions uint32
|
||||
}{ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_PERMISSIONS, 20, 0644}), &fileInfo{size: 20, mode: os.FileMode(0644), mtime: time.Unix(int64(0), 0)}, nil},
|
||||
}{sshFileXferAttrSize | sshFileXferAttrPermissions, 20, 0644}), &fileInfo{size: 20, mode: os.FileMode(0644), mtime: time.Unix(int64(0), 0)}, nil},
|
||||
{marshal(nil, struct {
|
||||
Flags uint32
|
||||
Size uint64
|
||||
UID, GID, Permissions uint32
|
||||
}{ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_UIDGID | ssh_FILEXFER_ATTR_UIDGID | ssh_FILEXFER_ATTR_PERMISSIONS, 20, 1000, 1000, 0644}), &fileInfo{size: 20, mode: os.FileMode(0644), mtime: time.Unix(int64(0), 0)}, nil},
|
||||
}{sshFileXferAttrSize | sshFileXferAttrUIDGID | sshFileXferAttrUIDGID | sshFileXferAttrPermissions, 20, 1000, 1000, 0644}), &fileInfo{size: 20, mode: os.FileMode(0644), mtime: time.Unix(int64(0), 0)}, nil},
|
||||
}
|
||||
|
||||
func TestUnmarshalAttrs(t *testing.T) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func fileStatFromInfoOs(fi os.FileInfo, flags *uint32, fileStat *FileStat) {
|
||||
if statt, ok := fi.Sys().(*syscall.Stat_t); ok {
|
||||
*flags |= ssh_FILEXFER_ATTR_UIDGID
|
||||
*flags |= sshFileXferAttrUIDGID
|
||||
fileStat.UID = statt.Uid
|
||||
fileStat.GID = statt.Gid
|
||||
}
|
||||
|
|
114
client.go
114
client.go
|
@ -15,12 +15,18 @@ import (
|
|||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
// InternalInconsistency indicates the packets sent and the data queued to be
|
||||
var (
|
||||
// ErrInternalInconsistency indicates the packets sent and the data queued to be
|
||||
// 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")
|
||||
ErrInternalInconsistency = errors.New("internal inconsistency")
|
||||
// InternalInconsistency alias for ErrInternalInconsistency.
|
||||
//
|
||||
// Deprecated: please use ErrInternalInconsistency
|
||||
InternalInconsistency = ErrInternalInconsistency
|
||||
)
|
||||
|
||||
// A ClientOption is a function which applies configuration to a Client.
|
||||
type ClientOption func(*Client) error
|
||||
|
@ -183,8 +189,8 @@ func (c *Client) recvVersion() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if typ != ssh_FXP_VERSION {
|
||||
return &unexpectedPacketErr{ssh_FXP_VERSION, typ}
|
||||
if typ != sshFxpVersion {
|
||||
return &unexpectedPacketErr{sshFxpVersion, typ}
|
||||
}
|
||||
|
||||
version, _ := unmarshalUint32(data)
|
||||
|
@ -222,7 +228,7 @@ func (c *Client) ReadDir(p string) ([]os.FileInfo, error) {
|
|||
break
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_NAME:
|
||||
case sshFxpName:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return nil, &unexpectedIDErr{id, sid}
|
||||
|
@ -239,7 +245,7 @@ func (c *Client) ReadDir(p string) ([]os.FileInfo, error) {
|
|||
}
|
||||
attrs = append(attrs, fileInfoFromStat(attr, path.Base(filename)))
|
||||
}
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
// TODO(dfc) scope warning!
|
||||
err = normaliseError(unmarshalStatus(id, data))
|
||||
done = true
|
||||
|
@ -263,14 +269,14 @@ func (c *Client) opendir(path string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_HANDLE:
|
||||
case sshFxpHandle:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return "", &unexpectedIDErr{id, sid}
|
||||
}
|
||||
handle, _ := unmarshalString(data)
|
||||
return handle, nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return "", normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return "", unimplementedPacketErr(typ)
|
||||
|
@ -289,14 +295,14 @@ func (c *Client) Stat(p string) (os.FileInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_ATTRS:
|
||||
case sshFxpAttrs:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return nil, &unexpectedIDErr{id, sid}
|
||||
}
|
||||
attr, _ := unmarshalAttrs(data)
|
||||
return fileInfoFromStat(attr, path.Base(p)), nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return nil, normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return nil, unimplementedPacketErr(typ)
|
||||
|
@ -315,14 +321,14 @@ func (c *Client) Lstat(p string) (os.FileInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_ATTRS:
|
||||
case sshFxpAttrs:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return nil, &unexpectedIDErr{id, sid}
|
||||
}
|
||||
attr, _ := unmarshalAttrs(data)
|
||||
return fileInfoFromStat(attr, path.Base(p)), nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return nil, normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return nil, unimplementedPacketErr(typ)
|
||||
|
@ -340,7 +346,7 @@ func (c *Client) ReadLink(p string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_NAME:
|
||||
case sshFxpName:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return "", &unexpectedIDErr{id, sid}
|
||||
|
@ -351,7 +357,7 @@ func (c *Client) ReadLink(p string) (string, error) {
|
|||
}
|
||||
filename, _ := unmarshalString(data) // ignore dummy attributes
|
||||
return filename, nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return "", normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return "", unimplementedPacketErr(typ)
|
||||
|
@ -370,7 +376,7 @@ func (c *Client) Link(oldname, newname string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -389,7 +395,7 @@ func (c *Client) Symlink(oldname, newname string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -409,7 +415,7 @@ func (c *Client) setstat(path string, flags uint32, attrs interface{}) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -423,7 +429,7 @@ func (c *Client) Chtimes(path string, atime time.Time, mtime time.Time) error {
|
|||
Mtime uint32
|
||||
}
|
||||
attrs := times{uint32(atime.Unix()), uint32(mtime.Unix())}
|
||||
return c.setstat(path, ssh_FILEXFER_ATTR_ACMODTIME, attrs)
|
||||
return c.setstat(path, sshFileXferAttrACmodTime, attrs)
|
||||
}
|
||||
|
||||
// Chown changes the user and group owners of the named file.
|
||||
|
@ -433,12 +439,12 @@ func (c *Client) Chown(path string, uid, gid int) error {
|
|||
GID uint32
|
||||
}
|
||||
attrs := owner{uint32(uid), uint32(gid)}
|
||||
return c.setstat(path, ssh_FILEXFER_ATTR_UIDGID, attrs)
|
||||
return c.setstat(path, sshFileXferAttrUIDGID, attrs)
|
||||
}
|
||||
|
||||
// Chmod changes the permissions of the named file.
|
||||
func (c *Client) Chmod(path string, mode os.FileMode) error {
|
||||
return c.setstat(path, ssh_FILEXFER_ATTR_PERMISSIONS, uint32(mode))
|
||||
return c.setstat(path, sshFileXferAttrPermissions, uint32(mode))
|
||||
}
|
||||
|
||||
// Truncate sets the size of the named file. Although it may be safely assumed
|
||||
|
@ -446,7 +452,7 @@ func (c *Client) Chmod(path string, mode os.FileMode) error {
|
|||
// the SFTP protocol does not specify what behavior the server should do when setting
|
||||
// size greater than the current size.
|
||||
func (c *Client) Truncate(path string, size int64) error {
|
||||
return c.setstat(path, ssh_FILEXFER_ATTR_SIZE, uint64(size))
|
||||
return c.setstat(path, sshFileXferAttrSize, uint64(size))
|
||||
}
|
||||
|
||||
// Open opens the named file for reading. If successful, methods on the
|
||||
|
@ -474,14 +480,14 @@ func (c *Client) open(path string, pflags uint32) (*File, error) {
|
|||
return nil, err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_HANDLE:
|
||||
case sshFxpHandle:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return nil, &unexpectedIDErr{id, sid}
|
||||
}
|
||||
handle, _ := unmarshalString(data)
|
||||
return &File{c: c, path: path, handle: handle}, nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return nil, normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return nil, unimplementedPacketErr(typ)
|
||||
|
@ -501,7 +507,7 @@ func (c *Client) close(handle string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -518,14 +524,14 @@ func (c *Client) fstat(handle string) (*FileStat, error) {
|
|||
return nil, err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_ATTRS:
|
||||
case sshFxpAttrs:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return nil, &unexpectedIDErr{id, sid}
|
||||
}
|
||||
attr, _ := unmarshalAttrs(data)
|
||||
return attr, nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return nil, normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return nil, unimplementedPacketErr(typ)
|
||||
|
@ -549,7 +555,7 @@ func (c *Client) StatVFS(path string) (*StatVFS, error) {
|
|||
|
||||
switch typ {
|
||||
// server responded with valid data
|
||||
case ssh_FXP_EXTENDED_REPLY:
|
||||
case sshFxpExtendedReply:
|
||||
var response StatVFS
|
||||
err = binary.Read(bytes.NewReader(data), binary.BigEndian, &response)
|
||||
if err != nil {
|
||||
|
@ -559,8 +565,8 @@ func (c *Client) StatVFS(path string) (*StatVFS, error) {
|
|||
return &response, nil
|
||||
|
||||
// the resquest failed
|
||||
case ssh_FXP_STATUS:
|
||||
return nil, errors.New(fxp(ssh_FXP_STATUS).String())
|
||||
case sshFxpStatus:
|
||||
return nil, errors.New(fxp(sshFxpStatus).String())
|
||||
|
||||
default:
|
||||
return nil, unimplementedPacketErr(typ)
|
||||
|
@ -581,7 +587,7 @@ func (c *Client) Remove(path string) error {
|
|||
switch err.Code {
|
||||
// some servers, *cough* osx *cough*, return EPERM, not ENODIR.
|
||||
// serv-u returns ssh_FX_FILE_IS_A_DIRECTORY
|
||||
case ssh_FX_PERMISSION_DENIED, ssh_FX_FAILURE, ssh_FX_FILE_IS_A_DIRECTORY:
|
||||
case sshFxPermissionDenied, sshFxFailure, sshFxFileIsADirectory:
|
||||
return c.RemoveDirectory(path)
|
||||
}
|
||||
}
|
||||
|
@ -598,7 +604,7 @@ func (c *Client) removeFile(path string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -616,7 +622,7 @@ func (c *Client) RemoveDirectory(path string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -635,7 +641,7 @@ func (c *Client) Rename(oldname, newname string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -655,7 +661,7 @@ func (c *Client) PosixRename(oldname, newname string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -672,7 +678,7 @@ func (c *Client) realpath(path string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_NAME:
|
||||
case sshFxpName:
|
||||
sid, data := unmarshalUint32(data)
|
||||
if sid != id {
|
||||
return "", &unexpectedIDErr{id, sid}
|
||||
|
@ -683,7 +689,7 @@ func (c *Client) realpath(path string) (string, error) {
|
|||
}
|
||||
filename, _ := unmarshalString(data) // ignore attributes
|
||||
return filename, nil
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return "", normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return "", unimplementedPacketErr(typ)
|
||||
|
@ -709,7 +715,7 @@ func (c *Client) Mkdir(path string) error {
|
|||
return err
|
||||
}
|
||||
switch typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return normaliseError(unmarshalStatus(id, data))
|
||||
default:
|
||||
return unimplementedPacketErr(typ)
|
||||
|
@ -864,14 +870,14 @@ func (f *File) Read(b []byte) (int, error) {
|
|||
}
|
||||
delete(reqs, reqID)
|
||||
switch res.typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
if firstErr.err == nil || req.offset < firstErr.offset {
|
||||
firstErr = offsetErr{
|
||||
offset: req.offset,
|
||||
err: normaliseError(unmarshalStatus(reqID, res.data)),
|
||||
}
|
||||
}
|
||||
case ssh_FXP_DATA:
|
||||
case sshFxpData:
|
||||
l, data := unmarshalUint32(data)
|
||||
n := copy(req.b, data[:l])
|
||||
read += n
|
||||
|
@ -953,7 +959,7 @@ func (f *File) WriteTo(w io.Writer) (int64, error) {
|
|||
|
||||
if inFlight == 0 {
|
||||
if firstErr.err == nil && len(pendingWrites) > 0 {
|
||||
return copied, InternalInconsistency
|
||||
return copied, ErrInternalInconsistency
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -971,11 +977,11 @@ func (f *File) WriteTo(w io.Writer) (int64, error) {
|
|||
}
|
||||
delete(reqs, reqID)
|
||||
switch res.typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
if firstErr.err == nil || req.offset < firstErr.offset {
|
||||
firstErr = offsetErr{offset: req.offset, err: normaliseError(unmarshalStatus(reqID, res.data))}
|
||||
}
|
||||
case ssh_FXP_DATA:
|
||||
case sshFxpData:
|
||||
l, data := unmarshalUint32(data)
|
||||
if req.offset == writeOffset {
|
||||
nbytes, err := w.Write(data)
|
||||
|
@ -1090,7 +1096,7 @@ func (f *File) Write(b []byte) (int, error) {
|
|||
continue
|
||||
}
|
||||
switch res.typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
id, _ := unmarshalUint32(res.data)
|
||||
err := normaliseError(unmarshalStatus(id, res.data))
|
||||
if err != nil && firstErr == nil {
|
||||
|
@ -1158,7 +1164,7 @@ func (f *File) ReadFrom(r io.Reader) (int64, error) {
|
|||
continue
|
||||
}
|
||||
switch res.typ {
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
id, _ := unmarshalUint32(res.data)
|
||||
err := normaliseError(unmarshalStatus(id, res.data))
|
||||
if err != nil && firstErr == nil {
|
||||
|
@ -1237,11 +1243,11 @@ func normaliseError(err error) error {
|
|||
switch err := err.(type) {
|
||||
case *StatusError:
|
||||
switch err.Code {
|
||||
case ssh_FX_EOF:
|
||||
case sshFxEOF:
|
||||
return io.EOF
|
||||
case ssh_FX_NO_SUCH_FILE:
|
||||
case sshFxNoSuchFile:
|
||||
return os.ErrNotExist
|
||||
case ssh_FX_OK:
|
||||
case sshFxOk:
|
||||
return nil
|
||||
default:
|
||||
return err
|
||||
|
@ -1279,24 +1285,24 @@ func flags(f int) uint32 {
|
|||
var out uint32
|
||||
switch f & os.O_WRONLY {
|
||||
case os.O_WRONLY:
|
||||
out |= ssh_FXF_WRITE
|
||||
out |= sshFxfWrite
|
||||
case os.O_RDONLY:
|
||||
out |= ssh_FXF_READ
|
||||
out |= sshFxfRead
|
||||
}
|
||||
if f&os.O_RDWR == os.O_RDWR {
|
||||
out |= ssh_FXF_READ | ssh_FXF_WRITE
|
||||
out |= sshFxfRead | sshFxfWrite
|
||||
}
|
||||
if f&os.O_APPEND == os.O_APPEND {
|
||||
out |= ssh_FXF_APPEND
|
||||
out |= sshFxfAppend
|
||||
}
|
||||
if f&os.O_CREATE == os.O_CREATE {
|
||||
out |= ssh_FXF_CREAT
|
||||
out |= sshFxfCreat
|
||||
}
|
||||
if f&os.O_TRUNC == os.O_TRUNC {
|
||||
out |= ssh_FXF_TRUNC
|
||||
out |= sshFxfTrunc
|
||||
}
|
||||
if f&os.O_EXCL == os.O_EXCL {
|
||||
out |= ssh_FXF_EXCL
|
||||
out |= sshFxfExcl
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ func TestClientStatVFS(t *testing.T) {
|
|||
if *testServerImpl {
|
||||
t.Skipf("go server does not support FXP_EXTENDED")
|
||||
}
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ func TestClientStatVFS(t *testing.T) {
|
|||
if *testServerImpl {
|
||||
t.Skipf("go server does not support FXP_EXTENDED")
|
||||
}
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
const (
|
||||
READONLY = true
|
||||
READWRITE = false
|
||||
NO_DELAY time.Duration = 0
|
||||
NODELAY time.Duration = 0
|
||||
|
||||
debuglevel = "ERROR" // set to "DEBUG" for debugging
|
||||
)
|
||||
|
@ -134,7 +134,7 @@ func testClientGoSvr(t testing.TB, readonly bool, delay time.Duration) (*Client,
|
|||
go server.Serve()
|
||||
|
||||
var ctx io.WriteCloser = c2
|
||||
if delay > NO_DELAY {
|
||||
if delay > NODELAY {
|
||||
ctx = newDelayedWriter(ctx, delay)
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ func testClient(t testing.TB, readonly bool, delay time.Duration) (*Client, *exe
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if delay > NO_DELAY {
|
||||
if delay > NODELAY {
|
||||
pw = newDelayedWriter(pw, delay)
|
||||
}
|
||||
pr, err := cmd.StdoutPipe()
|
||||
|
@ -187,7 +187,7 @@ func testClient(t testing.TB, readonly bool, delay time.Duration) (*Client, *exe
|
|||
}
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
|
||||
if err := sftp.Close(); err != nil {
|
||||
|
@ -196,7 +196,7 @@ func TestNewClient(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientLstat(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -223,7 +223,7 @@ func TestClientLstat(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientLstatIsNotExist(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -240,7 +240,7 @@ func TestClientLstatIsNotExist(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientMkdir(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -257,7 +257,7 @@ func TestClientMkdir(t *testing.T) {
|
|||
}
|
||||
}
|
||||
func TestClientMkdirAll(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -279,7 +279,7 @@ func TestClientMkdirAll(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientOpen(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -300,7 +300,7 @@ func TestClientOpen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientOpenIsNotExist(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -310,7 +310,7 @@ func TestClientOpenIsNotExist(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientStatIsNotExist(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -359,7 +359,7 @@ func (s seek) end(t *testing.T, r io.ReadSeeker) {
|
|||
}
|
||||
|
||||
func TestClientSeek(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -403,7 +403,7 @@ func TestClientSeek(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientCreate(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -422,7 +422,7 @@ func TestClientCreate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientAppend(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -441,7 +441,7 @@ func TestClientAppend(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientCreateFailed(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -453,8 +453,8 @@ func TestClientCreateFailed(t *testing.T) {
|
|||
defer os.Remove(f.Name())
|
||||
|
||||
f2, err := sftp.Create(f.Name())
|
||||
if err1, ok := err.(*StatusError); !ok || err1.Code != ssh_FX_PERMISSION_DENIED {
|
||||
t.Fatalf("Create: want: %v, got %#v", ssh_FX_PERMISSION_DENIED, err)
|
||||
if err1, ok := err.(*StatusError); !ok || err1.Code != sshFxPermissionDenied {
|
||||
t.Fatalf("Create: want: %v, got %#v", sshFxPermissionDenied, err)
|
||||
}
|
||||
if err == nil {
|
||||
f2.Close()
|
||||
|
@ -462,7 +462,7 @@ func TestClientCreateFailed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientFileName(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -483,7 +483,7 @@ func TestClientFileName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientFileStat(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -516,7 +516,7 @@ func TestClientFileStat(t *testing.T) {
|
|||
func TestClientStatLink(t *testing.T) {
|
||||
skipIfWindows(t) // Windows does not support links.
|
||||
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -576,7 +576,7 @@ func TestClientStatLink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientRemove(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -595,7 +595,7 @@ func TestClientRemove(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientRemoveDir(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -612,7 +612,7 @@ func TestClientRemoveDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientRemoveFailed(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -629,7 +629,7 @@ func TestClientRemoveFailed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientRename(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -652,7 +652,7 @@ func TestClientRename(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientPosixRename(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -675,7 +675,7 @@ func TestClientPosixRename(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientGetwd(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -696,7 +696,7 @@ func TestClientGetwd(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientReadLink(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -716,7 +716,7 @@ func TestClientReadLink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientLink(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -742,7 +742,7 @@ func TestClientLink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientSymlink(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -763,7 +763,7 @@ func TestClientSymlink(t *testing.T) {
|
|||
|
||||
func TestClientChmod(t *testing.T) {
|
||||
skipIfWindows(t) // No UNIX permissions.
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -785,7 +785,7 @@ func TestClientChmod(t *testing.T) {
|
|||
|
||||
func TestClientChmodReadonly(t *testing.T) {
|
||||
skipIfWindows(t) // No UNIX permissions.
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -802,7 +802,7 @@ func TestClientChmodReadonly(t *testing.T) {
|
|||
|
||||
func TestClientChown(t *testing.T) {
|
||||
skipIfWindows(t) // No UNIX permissions.
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -860,7 +860,7 @@ func TestClientChown(t *testing.T) {
|
|||
|
||||
func TestClientChownReadonly(t *testing.T) {
|
||||
skipIfWindows(t) // No UNIX permissions.
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -896,7 +896,7 @@ func TestClientChownReadonly(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientChtimes(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -918,7 +918,7 @@ func TestClientChtimes(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientChtimesReadonly(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -935,7 +935,7 @@ func TestClientChtimesReadonly(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientTruncate(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -961,7 +961,7 @@ func TestClientTruncate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientTruncateReadonly(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -994,7 +994,7 @@ func sameFile(want, got os.FileInfo) bool {
|
|||
}
|
||||
|
||||
func TestClientReadSimple(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1031,8 +1031,8 @@ func TestClientReadSimple(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientReadDir(t *testing.T) {
|
||||
sftp1, cmd1 := testClient(t, READONLY, NO_DELAY)
|
||||
sftp2, cmd2 := testClientGoSvr(t, READONLY, NO_DELAY)
|
||||
sftp1, cmd1 := testClient(t, READONLY, NODELAY)
|
||||
sftp2, cmd2 := testClientGoSvr(t, READONLY, NODELAY)
|
||||
defer cmd1.Wait()
|
||||
defer cmd2.Wait()
|
||||
defer sftp1.Close()
|
||||
|
@ -1124,7 +1124,7 @@ var clientReadTests = []struct {
|
|||
}
|
||||
|
||||
func TestClientRead(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1208,7 +1208,7 @@ var clientWriteTests = []struct {
|
|||
}
|
||||
|
||||
func TestClientWrite(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1245,7 +1245,7 @@ func TestClientWrite(t *testing.T) {
|
|||
|
||||
// ReadFrom is basically Write with io.Reader as the arg
|
||||
func TestClientReadFrom(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1285,7 +1285,7 @@ func TestClientReadFrom(t *testing.T) {
|
|||
// Deadlock would occur anytime desiredInFlight-inFlight==2 and 2 errors
|
||||
// occured in a row. The channel to report the errors only had a buffer
|
||||
// of 1 and 2 would be sent.
|
||||
var fakeNetErr = errors.New("Fake network issue")
|
||||
var errFakeNet = errors.New("Fake network issue")
|
||||
|
||||
func TestClientReadFromDeadlock(t *testing.T) {
|
||||
clientWriteDeadlock(t, 1, func(f *File) {
|
||||
|
@ -1295,7 +1295,7 @@ func TestClientReadFromDeadlock(t *testing.T) {
|
|||
if n != 0 {
|
||||
t.Fatal("Write should return 0", n)
|
||||
}
|
||||
if err != fakeNetErr {
|
||||
if err != errFakeNet {
|
||||
t.Fatal("Didn't recieve correct error", err)
|
||||
}
|
||||
})
|
||||
|
@ -1309,7 +1309,7 @@ func TestClientWriteDeadlock(t *testing.T) {
|
|||
if n != 0 {
|
||||
t.Fatal("Write should return 0", n)
|
||||
}
|
||||
if err != fakeNetErr {
|
||||
if err != errFakeNet {
|
||||
t.Fatal("Didn't recieve correct error", err)
|
||||
}
|
||||
})
|
||||
|
@ -1320,7 +1320,7 @@ func clientWriteDeadlock(t *testing.T, N int, badfunc func(*File)) {
|
|||
if !*testServerImpl {
|
||||
t.Skipf("skipping without -testserver")
|
||||
}
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1343,7 +1343,7 @@ func clientWriteDeadlock(t *testing.T, N int, badfunc func(*File)) {
|
|||
sendPacketTest := func(w io.Writer, m encoding.BinaryMarshaler) error {
|
||||
count++
|
||||
if count > N {
|
||||
return fakeNetErr
|
||||
return errFakeNet
|
||||
}
|
||||
return sendPacket(w, m)
|
||||
}
|
||||
|
@ -1364,7 +1364,7 @@ func TestClientReadDeadlock(t *testing.T) {
|
|||
if n != 0 {
|
||||
t.Fatal("Write should return 0", n)
|
||||
}
|
||||
if err != fakeNetErr {
|
||||
if err != errFakeNet {
|
||||
t.Fatal("Didn't recieve correct error", err)
|
||||
}
|
||||
})
|
||||
|
@ -1378,7 +1378,7 @@ func TestClientWriteToDeadlock(t *testing.T) {
|
|||
if n != 32768 {
|
||||
t.Fatal("Write should return 0", n)
|
||||
}
|
||||
if err != fakeNetErr {
|
||||
if err != errFakeNet {
|
||||
t.Fatal("Didn't recieve correct error", err)
|
||||
}
|
||||
})
|
||||
|
@ -1388,7 +1388,7 @@ func clientReadDeadlock(t *testing.T, N int, badfunc func(*File)) {
|
|||
if !*testServerImpl {
|
||||
t.Skipf("skipping without -testserver")
|
||||
}
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1421,7 +1421,7 @@ func clientReadDeadlock(t *testing.T, N int, badfunc func(*File)) {
|
|||
sendPacketTest := func(w io.Writer, m encoding.BinaryMarshaler) error {
|
||||
count++
|
||||
if count > N {
|
||||
return fakeNetErr
|
||||
return errFakeNet
|
||||
}
|
||||
return sendPacket(w, m)
|
||||
}
|
||||
|
@ -1522,7 +1522,7 @@ func mark(path string, info os.FileInfo, err error, errors *[]error, clear bool)
|
|||
}
|
||||
|
||||
func TestClientWalk(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1720,7 +1720,7 @@ func TestMatch(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGlob(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1749,7 +1749,7 @@ func TestGlob(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGlobError(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1760,7 +1760,7 @@ func TestGlobError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGlobUNC(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
// Just make sure this runs without crashing for now.
|
||||
|
@ -1774,7 +1774,7 @@ func TestServerRoughDisconnect(t *testing.T) {
|
|||
if *testServerImpl {
|
||||
t.Skipf("skipping with -testserver")
|
||||
}
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1799,7 +1799,7 @@ func TestServerRoughDisconnect2(t *testing.T) {
|
|||
if *testServerImpl {
|
||||
t.Skipf("skipping with -testserver")
|
||||
}
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READONLY, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1827,7 +1827,7 @@ func TestServerRoughDisconnect3(t *testing.T) {
|
|||
if *testServerImpl {
|
||||
t.Skipf("skipping with -testserver")
|
||||
}
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1855,7 +1855,7 @@ func TestServerRoughDisconnect4(t *testing.T) {
|
|||
if *testServerImpl {
|
||||
t.Skipf("skipping with -testserver")
|
||||
}
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1888,7 +1888,7 @@ func TestServerRoughDisconnect4(t *testing.T) {
|
|||
// sftp/issue/26 writing to a read only file caused client to loop.
|
||||
func TestClientWriteToROFile(t *testing.T) {
|
||||
skipIfWindows(t)
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
sftp, cmd := testClient(t, READWRITE, NODELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
|
@ -1943,31 +1943,31 @@ func benchmarkRead(b *testing.B, bufsize int, delay time.Duration) {
|
|||
}
|
||||
|
||||
func BenchmarkRead1k(b *testing.B) {
|
||||
benchmarkRead(b, 1*1024, NO_DELAY)
|
||||
benchmarkRead(b, 1*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead16k(b *testing.B) {
|
||||
benchmarkRead(b, 16*1024, NO_DELAY)
|
||||
benchmarkRead(b, 16*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead32k(b *testing.B) {
|
||||
benchmarkRead(b, 32*1024, NO_DELAY)
|
||||
benchmarkRead(b, 32*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead128k(b *testing.B) {
|
||||
benchmarkRead(b, 128*1024, NO_DELAY)
|
||||
benchmarkRead(b, 128*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead512k(b *testing.B) {
|
||||
benchmarkRead(b, 512*1024, NO_DELAY)
|
||||
benchmarkRead(b, 512*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead1MiB(b *testing.B) {
|
||||
benchmarkRead(b, 1024*1024, NO_DELAY)
|
||||
benchmarkRead(b, 1024*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead4MiB(b *testing.B) {
|
||||
benchmarkRead(b, 4*1024*1024, NO_DELAY)
|
||||
benchmarkRead(b, 4*1024*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkRead4MiBDelay10Msec(b *testing.B) {
|
||||
|
@ -2039,31 +2039,31 @@ func benchmarkWrite(b *testing.B, bufsize int, delay time.Duration) {
|
|||
}
|
||||
|
||||
func BenchmarkWrite1k(b *testing.B) {
|
||||
benchmarkWrite(b, 1*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 1*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite16k(b *testing.B) {
|
||||
benchmarkWrite(b, 16*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 16*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite32k(b *testing.B) {
|
||||
benchmarkWrite(b, 32*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 32*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite128k(b *testing.B) {
|
||||
benchmarkWrite(b, 128*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 128*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite512k(b *testing.B) {
|
||||
benchmarkWrite(b, 512*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 512*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite1MiB(b *testing.B) {
|
||||
benchmarkWrite(b, 1024*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 1024*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite4MiB(b *testing.B) {
|
||||
benchmarkWrite(b, 4*1024*1024, NO_DELAY)
|
||||
benchmarkWrite(b, 4*1024*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkWrite4MiBDelay10Msec(b *testing.B) {
|
||||
|
@ -2121,31 +2121,31 @@ func benchmarkReadFrom(b *testing.B, bufsize int, delay time.Duration) {
|
|||
}
|
||||
|
||||
func BenchmarkReadFrom1k(b *testing.B) {
|
||||
benchmarkReadFrom(b, 1*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 1*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom16k(b *testing.B) {
|
||||
benchmarkReadFrom(b, 16*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 16*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom32k(b *testing.B) {
|
||||
benchmarkReadFrom(b, 32*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 32*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom128k(b *testing.B) {
|
||||
benchmarkReadFrom(b, 128*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 128*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom512k(b *testing.B) {
|
||||
benchmarkReadFrom(b, 512*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 512*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom1MiB(b *testing.B) {
|
||||
benchmarkReadFrom(b, 1024*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 1024*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom4MiB(b *testing.B) {
|
||||
benchmarkReadFrom(b, 4*1024*1024, NO_DELAY)
|
||||
benchmarkReadFrom(b, 4*1024*1024, NODELAY)
|
||||
}
|
||||
|
||||
func BenchmarkReadFrom4MiBDelay10Msec(b *testing.B) {
|
||||
|
|
|
@ -18,10 +18,10 @@ var _ io.ReadWriteCloser = new(File)
|
|||
|
||||
func TestNormaliseError(t *testing.T) {
|
||||
var (
|
||||
ok = &StatusError{Code: ssh_FX_OK}
|
||||
eof = &StatusError{Code: ssh_FX_EOF}
|
||||
fail = &StatusError{Code: ssh_FX_FAILURE}
|
||||
noSuchFile = &StatusError{Code: ssh_FX_NO_SUCH_FILE}
|
||||
ok = &StatusError{Code: sshFxOk}
|
||||
eof = &StatusError{Code: sshFxEOF}
|
||||
fail = &StatusError{Code: sshFxFailure}
|
||||
noSuchFile = &StatusError{Code: sshFxNoSuchFile}
|
||||
foo = errors.New("foo")
|
||||
)
|
||||
|
||||
|
@ -72,11 +72,11 @@ var flagsTests = []struct {
|
|||
flags int
|
||||
want uint32
|
||||
}{
|
||||
{os.O_RDONLY, ssh_FXF_READ},
|
||||
{os.O_WRONLY, ssh_FXF_WRITE},
|
||||
{os.O_RDWR, ssh_FXF_READ | ssh_FXF_WRITE},
|
||||
{os.O_RDWR | os.O_CREATE | os.O_TRUNC, ssh_FXF_READ | ssh_FXF_WRITE | ssh_FXF_CREAT | ssh_FXF_TRUNC},
|
||||
{os.O_WRONLY | os.O_APPEND, ssh_FXF_WRITE | ssh_FXF_APPEND},
|
||||
{os.O_RDONLY, sshFxfRead},
|
||||
{os.O_WRONLY, sshFxfWrite},
|
||||
{os.O_RDWR, sshFxfRead | sshFxfWrite},
|
||||
{os.O_RDWR | os.O_CREATE | os.O_TRUNC, sshFxfRead | sshFxfWrite | sshFxfCreat | sshFxfTrunc},
|
||||
{os.O_WRONLY | os.O_APPEND, sshFxfWrite | sshFxfAppend},
|
||||
}
|
||||
|
||||
func TestFlags(t *testing.T) {
|
||||
|
@ -92,7 +92,7 @@ func TestUnmarshalStatus(t *testing.T) {
|
|||
requestID := uint32(1)
|
||||
|
||||
id := marshalUint32([]byte{}, requestID)
|
||||
idCode := marshalUint32(id, ssh_FX_FAILURE)
|
||||
idCode := marshalUint32(id, sshFxFailure)
|
||||
idCodeMsg := marshalString(idCode, "err msg")
|
||||
idCodeMsgLang := marshalString(idCodeMsg, "lang tag")
|
||||
|
||||
|
@ -107,7 +107,7 @@ func TestUnmarshalStatus(t *testing.T) {
|
|||
reqID: 1,
|
||||
status: idCodeMsgLang,
|
||||
want: &StatusError{
|
||||
Code: ssh_FX_FAILURE,
|
||||
Code: sshFxFailure,
|
||||
msg: "err msg",
|
||||
lang: "lang tag",
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ func TestUnmarshalStatus(t *testing.T) {
|
|||
reqID: 1,
|
||||
status: idCode,
|
||||
want: &StatusError{
|
||||
Code: ssh_FX_FAILURE,
|
||||
Code: sshFxFailure,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ func TestUnmarshalStatus(t *testing.T) {
|
|||
reqID: 1,
|
||||
status: idCodeMsg,
|
||||
want: &StatusError{
|
||||
Code: ssh_FX_FAILURE,
|
||||
Code: sshFxFailure,
|
||||
msg: "err msg",
|
||||
},
|
||||
},
|
||||
|
|
|
@ -39,7 +39,7 @@ func newPktMgr(sender packetSender) *packetManager {
|
|||
}
|
||||
|
||||
//// packet ordering
|
||||
func (s *packetManager) newOrderId() uint32 {
|
||||
func (s *packetManager) newOrderID() uint32 {
|
||||
s.packetCount++
|
||||
return s.packetCount
|
||||
}
|
||||
|
@ -50,10 +50,10 @@ type orderedRequest struct {
|
|||
}
|
||||
|
||||
func (s *packetManager) newOrderedRequest(p requestPacket) orderedRequest {
|
||||
return orderedRequest{requestPacket: p, orderid: s.newOrderId()}
|
||||
return orderedRequest{requestPacket: p, orderid: s.newOrderID()}
|
||||
}
|
||||
func (p orderedRequest) orderId() uint32 { return p.orderid }
|
||||
func (p orderedRequest) setOrderId(oid uint32) { p.orderid = oid }
|
||||
func (p orderedRequest) orderID() uint32 { return p.orderid }
|
||||
func (p orderedRequest) setOrderID(oid uint32) { p.orderid = oid }
|
||||
|
||||
type orderedResponse struct {
|
||||
responsePacket
|
||||
|
@ -64,18 +64,18 @@ func (s *packetManager) newOrderedResponse(p responsePacket, id uint32,
|
|||
) orderedResponse {
|
||||
return orderedResponse{responsePacket: p, orderid: id}
|
||||
}
|
||||
func (p orderedResponse) orderId() uint32 { return p.orderid }
|
||||
func (p orderedResponse) setOrderId(oid uint32) { p.orderid = oid }
|
||||
func (p orderedResponse) orderID() uint32 { return p.orderid }
|
||||
func (p orderedResponse) setOrderID(oid uint32) { p.orderid = oid }
|
||||
|
||||
type orderedPacket interface {
|
||||
id() uint32
|
||||
orderId() uint32
|
||||
orderID() uint32
|
||||
}
|
||||
type orderedPackets []orderedPacket
|
||||
|
||||
func (o orderedPackets) Sort() {
|
||||
sort.Slice(o, func(i, j int) bool {
|
||||
return o[i].orderId() < o[j].orderId()
|
||||
return o[i].orderID() < o[j].orderID()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -145,11 +145,11 @@ func (s *packetManager) controller() {
|
|||
for {
|
||||
select {
|
||||
case pkt := <-s.requests:
|
||||
debug("incoming id (oid): %v (%v)", pkt.id(), pkt.orderId())
|
||||
debug("incoming id (oid): %v (%v)", pkt.id(), pkt.orderID())
|
||||
s.incoming = append(s.incoming, pkt)
|
||||
s.incoming.Sort()
|
||||
case pkt := <-s.responses:
|
||||
debug("outgoing id (oid): %v (%v)", pkt.id(), pkt.orderId())
|
||||
debug("outgoing id (oid): %v (%v)", pkt.id(), pkt.orderID())
|
||||
s.outgoing = append(s.outgoing, pkt)
|
||||
s.outgoing.Sort()
|
||||
case <-s.fini:
|
||||
|
@ -171,7 +171,7 @@ func (s *packetManager) maybeSendPackets() {
|
|||
in := s.incoming[0]
|
||||
// debug("incoming: %v", ids(s.incoming))
|
||||
// debug("outgoing: %v", ids(s.outgoing))
|
||||
if in.orderId() == out.orderId() {
|
||||
if in.orderID() == out.orderID() {
|
||||
debug("Sending packet: %v", out.id())
|
||||
s.sender.sendPacket(out.(encoding.BinaryMarshaler))
|
||||
// pop off heads
|
||||
|
|
|
@ -46,7 +46,7 @@ type pair struct {
|
|||
in, out fakepacket
|
||||
}
|
||||
|
||||
type ordered_pair struct {
|
||||
type orderedPair struct {
|
||||
in orderedRequest
|
||||
out orderedResponse
|
||||
}
|
||||
|
@ -91,17 +91,17 @@ func TestPacketManager(t *testing.T) {
|
|||
|
||||
for i := range tables {
|
||||
table := tables[i]
|
||||
ordered_pairs := make([]ordered_pair, 0, len(table))
|
||||
orderedPairs := make([]orderedPair, 0, len(table))
|
||||
for _, p := range table {
|
||||
ordered_pairs = append(ordered_pairs, ordered_pair{
|
||||
orderedPairs = append(orderedPairs, orderedPair{
|
||||
in: orderedRequest{p.in, p.in.oid},
|
||||
out: orderedResponse{p.out, p.out.oid},
|
||||
})
|
||||
}
|
||||
for _, p := range ordered_pairs {
|
||||
for _, p := range orderedPairs {
|
||||
s.incomingPacket(p.in)
|
||||
}
|
||||
for _, p := range ordered_pairs {
|
||||
for _, p := range orderedPairs {
|
||||
s.readyPacket(p.out)
|
||||
}
|
||||
for _, p := range table {
|
||||
|
|
|
@ -84,45 +84,45 @@ func (p sshFxVersionPacket) id() uint32 { return 0 }
|
|||
func makePacket(p rxPacket) (requestPacket, error) {
|
||||
var pkt requestPacket
|
||||
switch p.pktType {
|
||||
case ssh_FXP_INIT:
|
||||
case sshFxpInit:
|
||||
pkt = &sshFxInitPacket{}
|
||||
case ssh_FXP_LSTAT:
|
||||
case sshFxpLstat:
|
||||
pkt = &sshFxpLstatPacket{}
|
||||
case ssh_FXP_OPEN:
|
||||
case sshFxpOpen:
|
||||
pkt = &sshFxpOpenPacket{}
|
||||
case ssh_FXP_CLOSE:
|
||||
case sshFxpClose:
|
||||
pkt = &sshFxpClosePacket{}
|
||||
case ssh_FXP_READ:
|
||||
case sshFxpRead:
|
||||
pkt = &sshFxpReadPacket{}
|
||||
case ssh_FXP_WRITE:
|
||||
case sshFxpWrite:
|
||||
pkt = &sshFxpWritePacket{}
|
||||
case ssh_FXP_FSTAT:
|
||||
case sshFxpFstat:
|
||||
pkt = &sshFxpFstatPacket{}
|
||||
case ssh_FXP_SETSTAT:
|
||||
case sshFxpSetstat:
|
||||
pkt = &sshFxpSetstatPacket{}
|
||||
case ssh_FXP_FSETSTAT:
|
||||
case sshFxpFsetstat:
|
||||
pkt = &sshFxpFsetstatPacket{}
|
||||
case ssh_FXP_OPENDIR:
|
||||
case sshFxpOpendir:
|
||||
pkt = &sshFxpOpendirPacket{}
|
||||
case ssh_FXP_READDIR:
|
||||
case sshFxpReaddir:
|
||||
pkt = &sshFxpReaddirPacket{}
|
||||
case ssh_FXP_REMOVE:
|
||||
case sshFxpRemove:
|
||||
pkt = &sshFxpRemovePacket{}
|
||||
case ssh_FXP_MKDIR:
|
||||
case sshFxpMkdir:
|
||||
pkt = &sshFxpMkdirPacket{}
|
||||
case ssh_FXP_RMDIR:
|
||||
case sshFxpRmdir:
|
||||
pkt = &sshFxpRmdirPacket{}
|
||||
case ssh_FXP_REALPATH:
|
||||
case sshFxpRealpath:
|
||||
pkt = &sshFxpRealpathPacket{}
|
||||
case ssh_FXP_STAT:
|
||||
case sshFxpStat:
|
||||
pkt = &sshFxpStatPacket{}
|
||||
case ssh_FXP_RENAME:
|
||||
case sshFxpRename:
|
||||
pkt = &sshFxpRenamePacket{}
|
||||
case ssh_FXP_READLINK:
|
||||
case sshFxpReadlink:
|
||||
pkt = &sshFxpReadlinkPacket{}
|
||||
case ssh_FXP_SYMLINK:
|
||||
case sshFxpSymlink:
|
||||
pkt = &sshFxpSymlinkPacket{}
|
||||
case ssh_FXP_EXTENDED:
|
||||
case sshFxpExtended:
|
||||
pkt = &sshFxpExtendedPacket{}
|
||||
default:
|
||||
return nil, errors.Errorf("unhandled packet type: %s", p.pktType)
|
||||
|
|
58
packet.go
58
packet.go
|
@ -189,7 +189,7 @@ func (p sshFxInitPacket) MarshalBinary() ([]byte, error) {
|
|||
}
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_INIT)
|
||||
b = append(b, sshFxpInit)
|
||||
b = marshalUint32(b, p.Version)
|
||||
for _, e := range p.Extensions {
|
||||
b = marshalString(b, e.Name)
|
||||
|
@ -230,7 +230,7 @@ func (p sshFxVersionPacket) MarshalBinary() ([]byte, error) {
|
|||
}
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_VERSION)
|
||||
b = append(b, sshFxpVersion)
|
||||
b = marshalUint32(b, p.Version)
|
||||
for _, e := range p.Extensions {
|
||||
b = marshalString(b, e.Name)
|
||||
|
@ -268,7 +268,7 @@ type sshFxpReaddirPacket struct {
|
|||
func (p sshFxpReaddirPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpReaddirPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_READDIR, p.ID, p.Handle)
|
||||
return marshalIDString(sshFxpReaddir, p.ID, p.Handle)
|
||||
}
|
||||
|
||||
func (p *sshFxpReaddirPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -283,7 +283,7 @@ type sshFxpOpendirPacket struct {
|
|||
func (p sshFxpOpendirPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpOpendirPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_OPENDIR, p.ID, p.Path)
|
||||
return marshalIDString(sshFxpOpendir, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpOpendirPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -298,7 +298,7 @@ type sshFxpLstatPacket struct {
|
|||
func (p sshFxpLstatPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpLstatPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_LSTAT, p.ID, p.Path)
|
||||
return marshalIDString(sshFxpLstat, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpLstatPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -313,7 +313,7 @@ type sshFxpStatPacket struct {
|
|||
func (p sshFxpStatPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpStatPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_STAT, p.ID, p.Path)
|
||||
return marshalIDString(sshFxpStat, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpStatPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -328,7 +328,7 @@ type sshFxpFstatPacket struct {
|
|||
func (p sshFxpFstatPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpFstatPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_FSTAT, p.ID, p.Handle)
|
||||
return marshalIDString(sshFxpFstat, p.ID, p.Handle)
|
||||
}
|
||||
|
||||
func (p *sshFxpFstatPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -343,7 +343,7 @@ type sshFxpClosePacket struct {
|
|||
func (p sshFxpClosePacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpClosePacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_CLOSE, p.ID, p.Handle)
|
||||
return marshalIDString(sshFxpClose, p.ID, p.Handle)
|
||||
}
|
||||
|
||||
func (p *sshFxpClosePacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -358,7 +358,7 @@ type sshFxpRemovePacket struct {
|
|||
func (p sshFxpRemovePacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpRemovePacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_REMOVE, p.ID, p.Filename)
|
||||
return marshalIDString(sshFxpRemove, p.ID, p.Filename)
|
||||
}
|
||||
|
||||
func (p *sshFxpRemovePacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -373,7 +373,7 @@ type sshFxpRmdirPacket struct {
|
|||
func (p sshFxpRmdirPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpRmdirPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_RMDIR, p.ID, p.Path)
|
||||
return marshalIDString(sshFxpRmdir, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpRmdirPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -394,7 +394,7 @@ func (p sshFxpSymlinkPacket) MarshalBinary() ([]byte, error) {
|
|||
4 + len(p.Linkpath)
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_SYMLINK)
|
||||
b = append(b, sshFxpSymlink)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Targetpath)
|
||||
b = marshalString(b, p.Linkpath)
|
||||
|
@ -429,7 +429,7 @@ func (p sshFxpHardlinkPacket) MarshalBinary() ([]byte, error) {
|
|||
4 + len(p.Newpath)
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_EXTENDED)
|
||||
b = append(b, sshFxpExtended)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, ext)
|
||||
b = marshalString(b, p.Oldpath)
|
||||
|
@ -445,7 +445,7 @@ type sshFxpReadlinkPacket struct {
|
|||
func (p sshFxpReadlinkPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpReadlinkPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_READLINK, p.ID, p.Path)
|
||||
return marshalIDString(sshFxpReadlink, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpReadlinkPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -460,7 +460,7 @@ type sshFxpRealpathPacket struct {
|
|||
func (p sshFxpRealpathPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpRealpathPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_REALPATH, p.ID, p.Path)
|
||||
return marshalIDString(sshFxpRealpath, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpRealpathPacket) UnmarshalBinary(b []byte) error {
|
||||
|
@ -490,7 +490,7 @@ type sshFxpNamePacket struct {
|
|||
|
||||
func (p sshFxpNamePacket) MarshalBinary() ([]byte, error) {
|
||||
b := []byte{}
|
||||
b = append(b, ssh_FXP_NAME)
|
||||
b = append(b, sshFxpName)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalUint32(b, uint32(len(p.NameAttrs)))
|
||||
for _, na := range p.NameAttrs {
|
||||
|
@ -519,7 +519,7 @@ func (p sshFxpOpenPacket) MarshalBinary() ([]byte, error) {
|
|||
4 + 4
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_OPEN)
|
||||
b = append(b, sshFxpOpen)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Path)
|
||||
b = marshalUint32(b, p.Pflags)
|
||||
|
@ -556,7 +556,7 @@ func (p sshFxpReadPacket) MarshalBinary() ([]byte, error) {
|
|||
8 + 4 // uint64 + uint32
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_READ)
|
||||
b = append(b, sshFxpRead)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Handle)
|
||||
b = marshalUint64(b, p.Offset)
|
||||
|
@ -592,7 +592,7 @@ func (p sshFxpRenamePacket) MarshalBinary() ([]byte, error) {
|
|||
4 + len(p.Newpath)
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_RENAME)
|
||||
b = append(b, sshFxpRename)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Oldpath)
|
||||
b = marshalString(b, p.Newpath)
|
||||
|
@ -627,7 +627,7 @@ func (p sshFxpPosixRenamePacket) MarshalBinary() ([]byte, error) {
|
|||
4 + len(p.Newpath)
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_EXTENDED)
|
||||
b = append(b, sshFxpExtended)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, ext)
|
||||
b = marshalString(b, p.Oldpath)
|
||||
|
@ -652,7 +652,7 @@ func (p sshFxpWritePacket) MarshalBinary() ([]byte, error) {
|
|||
len(p.Data)
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_WRITE)
|
||||
b = append(b, sshFxpWrite)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Handle)
|
||||
b = marshalUint64(b, p.Offset)
|
||||
|
@ -693,7 +693,7 @@ func (p sshFxpMkdirPacket) MarshalBinary() ([]byte, error) {
|
|||
4 // uint32
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_MKDIR)
|
||||
b = append(b, sshFxpMkdir)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Path)
|
||||
b = marshalUint32(b, p.Flags)
|
||||
|
@ -735,7 +735,7 @@ func (p sshFxpSetstatPacket) MarshalBinary() ([]byte, error) {
|
|||
4 // uint32 + uint64
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_SETSTAT)
|
||||
b = append(b, sshFxpSetstat)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Path)
|
||||
b = marshalUint32(b, p.Flags)
|
||||
|
@ -749,7 +749,7 @@ func (p sshFxpFsetstatPacket) MarshalBinary() ([]byte, error) {
|
|||
4 // uint32 + uint64
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_FSETSTAT)
|
||||
b = append(b, sshFxpFsetstat)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Handle)
|
||||
b = marshalUint32(b, p.Flags)
|
||||
|
@ -789,7 +789,7 @@ type sshFxpHandlePacket struct {
|
|||
}
|
||||
|
||||
func (p sshFxpHandlePacket) MarshalBinary() ([]byte, error) {
|
||||
b := []byte{ssh_FXP_HANDLE}
|
||||
b := []byte{sshFxpHandle}
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Handle)
|
||||
return b, nil
|
||||
|
@ -801,7 +801,7 @@ type sshFxpStatusPacket struct {
|
|||
}
|
||||
|
||||
func (p sshFxpStatusPacket) MarshalBinary() ([]byte, error) {
|
||||
b := []byte{ssh_FXP_STATUS}
|
||||
b := []byte{sshFxpStatus}
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalStatus(b, p.StatusError)
|
||||
return b, nil
|
||||
|
@ -814,7 +814,7 @@ type sshFxpDataPacket struct {
|
|||
}
|
||||
|
||||
func (p sshFxpDataPacket) MarshalBinary() ([]byte, error) {
|
||||
b := []byte{ssh_FXP_DATA}
|
||||
b := []byte{sshFxpData}
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalUint32(b, p.Length)
|
||||
b = append(b, p.Data[:p.Length]...)
|
||||
|
@ -849,7 +849,7 @@ func (p sshFxpStatvfsPacket) MarshalBinary() ([]byte, error) {
|
|||
len("statvfs@openssh.com")
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_EXTENDED)
|
||||
b = append(b, sshFxpExtended)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, "statvfs@openssh.com")
|
||||
b = marshalString(b, p.Path)
|
||||
|
@ -882,10 +882,10 @@ func (p *StatVFS) FreeSpace() uint64 {
|
|||
return p.Frsize * p.Bfree
|
||||
}
|
||||
|
||||
// Convert to ssh_FXP_EXTENDED_REPLY packet binary format
|
||||
// MarshalBinary converts to ssh_FXP_EXTENDED_REPLY packet binary format
|
||||
func (p *StatVFS) MarshalBinary() ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.Write([]byte{ssh_FXP_EXTENDED_REPLY})
|
||||
buf.Write([]byte{sshFxpExtendedReply})
|
||||
err := binary.Write(&buf, binary.BigEndian, p)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ var recvPacketTests = []struct {
|
|||
Extensions: []extensionPair{
|
||||
{"posix-rename@openssh.com", "1"},
|
||||
},
|
||||
}), ssh_FXP_INIT, []byte{0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x18, 0x70, 0x6f, 0x73, 0x69, 0x78, 0x2d, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x0, 0x1, 0x31}},
|
||||
}), sshFxpInit, []byte{0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x18, 0x70, 0x6f, 0x73, 0x69, 0x78, 0x2d, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x0, 0x1, 0x31}},
|
||||
}
|
||||
|
||||
func TestRecvPacket(t *testing.T) {
|
||||
|
@ -219,15 +219,15 @@ func TestSSHFxpOpenPacketreadonly(t *testing.T) {
|
|||
ok bool
|
||||
}{
|
||||
{
|
||||
pflags: ssh_FXF_READ,
|
||||
pflags: sshFxfRead,
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
pflags: ssh_FXF_WRITE,
|
||||
pflags: sshFxfWrite,
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
pflags: ssh_FXF_READ | ssh_FXF_WRITE,
|
||||
pflags: sshFxfRead | sshFxfWrite,
|
||||
ok: false,
|
||||
},
|
||||
}
|
||||
|
@ -253,32 +253,32 @@ func TestSSHFxpOpenPackethasPflags(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "have read, test against write",
|
||||
haveFlags: ssh_FXF_READ,
|
||||
testFlags: []uint32{ssh_FXF_WRITE},
|
||||
haveFlags: sshFxfRead,
|
||||
testFlags: []uint32{sshFxfWrite},
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
desc: "have write, test against read",
|
||||
haveFlags: ssh_FXF_WRITE,
|
||||
testFlags: []uint32{ssh_FXF_READ},
|
||||
haveFlags: sshFxfWrite,
|
||||
testFlags: []uint32{sshFxfRead},
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
desc: "have read+write, test against read",
|
||||
haveFlags: ssh_FXF_READ | ssh_FXF_WRITE,
|
||||
testFlags: []uint32{ssh_FXF_READ},
|
||||
haveFlags: sshFxfRead | sshFxfWrite,
|
||||
testFlags: []uint32{sshFxfRead},
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
desc: "have read+write, test against write",
|
||||
haveFlags: ssh_FXF_READ | ssh_FXF_WRITE,
|
||||
testFlags: []uint32{ssh_FXF_WRITE},
|
||||
haveFlags: sshFxfRead | sshFxfWrite,
|
||||
testFlags: []uint32{sshFxfWrite},
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
desc: "have read+write, test against read+write",
|
||||
haveFlags: ssh_FXF_READ | ssh_FXF_WRITE,
|
||||
testFlags: []uint32{ssh_FXF_READ, ssh_FXF_WRITE},
|
||||
haveFlags: sshFxfRead | sshFxfWrite,
|
||||
testFlags: []uint32{sshFxfRead, sshFxfWrite},
|
||||
ok: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package sftp
|
|||
// request and AttrFlags() and Attributes() when working with SetStat requests.
|
||||
import "os"
|
||||
|
||||
// File Open and Write Flags. Correlate directly with with os.OpenFile flags
|
||||
// FileOpenFlags defines Open and Write Flags. Correlate directly with with os.OpenFile flags
|
||||
// (https://golang.org/pkg/os/#pkg-constants).
|
||||
type FileOpenFlags struct {
|
||||
Read, Write, Append, Creat, Trunc, Excl bool
|
||||
|
@ -13,12 +13,12 @@ type FileOpenFlags struct {
|
|||
|
||||
func newFileOpenFlags(flags uint32) FileOpenFlags {
|
||||
return FileOpenFlags{
|
||||
Read: flags&ssh_FXF_READ != 0,
|
||||
Write: flags&ssh_FXF_WRITE != 0,
|
||||
Append: flags&ssh_FXF_APPEND != 0,
|
||||
Creat: flags&ssh_FXF_CREAT != 0,
|
||||
Trunc: flags&ssh_FXF_TRUNC != 0,
|
||||
Excl: flags&ssh_FXF_EXCL != 0,
|
||||
Read: flags&sshFxfRead != 0,
|
||||
Write: flags&sshFxfWrite != 0,
|
||||
Append: flags&sshFxfAppend != 0,
|
||||
Creat: flags&sshFxfCreat != 0,
|
||||
Trunc: flags&sshFxfTrunc != 0,
|
||||
Excl: flags&sshFxfExcl != 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ func (r *Request) Pflags() FileOpenFlags {
|
|||
return newFileOpenFlags(r.Flags)
|
||||
}
|
||||
|
||||
// Flags that indicate whether SFTP file attributes were passed. When a flag is
|
||||
// FileAttrFlags that indicate whether SFTP file attributes were passed. When a flag is
|
||||
// true the corresponding attribute should be available from the FileStat
|
||||
// object returned by Attributes method. Used with SetStat.
|
||||
type FileAttrFlags struct {
|
||||
|
@ -37,14 +37,14 @@ type FileAttrFlags struct {
|
|||
|
||||
func newFileAttrFlags(flags uint32) FileAttrFlags {
|
||||
return FileAttrFlags{
|
||||
Size: (flags & ssh_FILEXFER_ATTR_SIZE) != 0,
|
||||
UidGid: (flags & ssh_FILEXFER_ATTR_UIDGID) != 0,
|
||||
Permissions: (flags & ssh_FILEXFER_ATTR_PERMISSIONS) != 0,
|
||||
Acmodtime: (flags & ssh_FILEXFER_ATTR_ACMODTIME) != 0,
|
||||
Size: (flags & sshFileXferAttrSize) != 0,
|
||||
UidGid: (flags & sshFileXferAttrUIDGID) != 0,
|
||||
Permissions: (flags & sshFileXferAttrPermissions) != 0,
|
||||
Acmodtime: (flags & sshFileXferAttrACmodTime) != 0,
|
||||
}
|
||||
}
|
||||
|
||||
// FileAttrFlags returns a FileAttrFlags boolean struct based on the
|
||||
// AttrFlags returns a FileAttrFlags boolean struct based on the
|
||||
// bitmap/uint32 file attribute flags from the SFTP packaet.
|
||||
func (r *Request) AttrFlags() FileAttrFlags {
|
||||
return newFileAttrFlags(r.Flags)
|
||||
|
@ -55,7 +55,7 @@ func (a FileStat) FileMode() os.FileMode {
|
|||
return os.FileMode(a.Mode)
|
||||
}
|
||||
|
||||
// Attributres parses file attributes byte blob and return them in a
|
||||
// Attributes parses file attributes byte blob and return them in a
|
||||
// FileStat object.
|
||||
func (r *Request) Attributes() *FileStat {
|
||||
fs, _ := getFileStat(r.Flags, r.Attrs)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func TestRequestPflags(t *testing.T) {
|
||||
pflags := newFileOpenFlags(ssh_FXF_READ | ssh_FXF_WRITE | ssh_FXF_APPEND)
|
||||
pflags := newFileOpenFlags(sshFxfRead | sshFxfWrite | sshFxfAppend)
|
||||
assert.True(t, pflags.Read)
|
||||
assert.True(t, pflags.Write)
|
||||
assert.True(t, pflags.Append)
|
||||
|
@ -20,7 +20,7 @@ func TestRequestPflags(t *testing.T) {
|
|||
|
||||
func TestRequestAflags(t *testing.T) {
|
||||
aflags := newFileAttrFlags(
|
||||
ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_UIDGID)
|
||||
sshFileXferAttrSize | sshFileXferAttrUIDGID)
|
||||
assert.True(t, aflags.Size)
|
||||
assert.True(t, aflags.UidGid)
|
||||
assert.False(t, aflags.Acmodtime)
|
||||
|
@ -30,22 +30,22 @@ func TestRequestAflags(t *testing.T) {
|
|||
func TestRequestAttributes(t *testing.T) {
|
||||
// UID/GID
|
||||
fa := FileStat{UID: 1, GID: 2}
|
||||
fl := uint32(ssh_FILEXFER_ATTR_UIDGID)
|
||||
fl := uint32(sshFileXferAttrUIDGID)
|
||||
at := []byte{}
|
||||
at = marshalUint32(at, 1)
|
||||
at = marshalUint32(at, 2)
|
||||
test_fs, _ := getFileStat(fl, at)
|
||||
assert.Equal(t, fa, *test_fs)
|
||||
testFs, _ := getFileStat(fl, at)
|
||||
assert.Equal(t, fa, *testFs)
|
||||
// Size and Mode
|
||||
fa = FileStat{Mode: 700, Size: 99}
|
||||
fl = uint32(ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_PERMISSIONS)
|
||||
fl = uint32(sshFileXferAttrSize | sshFileXferAttrPermissions)
|
||||
at = []byte{}
|
||||
at = marshalUint64(at, 99)
|
||||
at = marshalUint32(at, 700)
|
||||
test_fs, _ = getFileStat(fl, at)
|
||||
assert.Equal(t, fa, *test_fs)
|
||||
testFs, _ = getFileStat(fl, at)
|
||||
assert.Equal(t, fa, *testFs)
|
||||
// FileMode
|
||||
assert.True(t, test_fs.FileMode().IsRegular())
|
||||
assert.False(t, test_fs.FileMode().IsDir())
|
||||
assert.Equal(t, test_fs.FileMode().Perm(), os.FileMode(700).Perm())
|
||||
assert.True(t, testFs.FileMode().IsRegular())
|
||||
assert.False(t, testFs.FileMode().IsDir())
|
||||
assert.Equal(t, testFs.FileMode().Perm(), os.FileMode(700).Perm())
|
||||
}
|
||||
|
|
|
@ -1,40 +1,52 @@
|
|||
package sftp
|
||||
|
||||
type fxerr uint32
|
||||
|
||||
// Error types that match the SFTP's SSH_FXP_STATUS codes. Gives you more
|
||||
// direct control of the errors being sent vs. letting the library work them
|
||||
// out from the standard os/io errors.
|
||||
|
||||
type fxerr uint32
|
||||
|
||||
const (
|
||||
ErrSshFxOk = fxerr(ssh_FX_OK)
|
||||
ErrSshFxEof = fxerr(ssh_FX_EOF)
|
||||
ErrSshFxNoSuchFile = fxerr(ssh_FX_NO_SUCH_FILE)
|
||||
ErrSshFxPermissionDenied = fxerr(ssh_FX_PERMISSION_DENIED)
|
||||
ErrSshFxFailure = fxerr(ssh_FX_FAILURE)
|
||||
ErrSshFxBadMessage = fxerr(ssh_FX_BAD_MESSAGE)
|
||||
ErrSshFxNoConnection = fxerr(ssh_FX_NO_CONNECTION)
|
||||
ErrSshFxConnectionLost = fxerr(ssh_FX_CONNECTION_LOST)
|
||||
ErrSshFxOpUnsupported = fxerr(ssh_FX_OP_UNSUPPORTED)
|
||||
ErrSSHFxOk = fxerr(sshFxOk)
|
||||
ErrSSHFxEOF = fxerr(sshFxEOF)
|
||||
ErrSSHFxNoSuchFile = fxerr(sshFxNoSuchFile)
|
||||
ErrSSHFxPermissionDenied = fxerr(sshFxPermissionDenied)
|
||||
ErrSSHFxFailure = fxerr(sshFxFailure)
|
||||
ErrSSHFxBadMessage = fxerr(sshFxBadMessage)
|
||||
ErrSSHFxNoConnection = fxerr(sshFxNoConnection)
|
||||
ErrSSHFxConnectionLost = fxerr(sshFxConnectionLost)
|
||||
ErrSSHFxOpUnsupported = fxerr(sshFxOPUnsupported)
|
||||
)
|
||||
|
||||
// Deprecated error types, these are aliases for the new ones, please use the new ones directly
|
||||
const (
|
||||
ErrSshFxOk = ErrSSHFxOk
|
||||
ErrSshFxEof = ErrSSHFxEOF
|
||||
ErrSshFxNoSuchFile = ErrSSHFxNoSuchFile
|
||||
ErrSshFxPermissionDenied = ErrSSHFxPermissionDenied
|
||||
ErrSshFxFailure = ErrSSHFxFailure
|
||||
ErrSshFxBadMessage = ErrSSHFxBadMessage
|
||||
ErrSshFxNoConnection = ErrSSHFxNoConnection
|
||||
ErrSshFxConnectionLost = ErrSSHFxConnectionLost
|
||||
ErrSshFxOpUnsupported = ErrSSHFxOpUnsupported
|
||||
)
|
||||
|
||||
func (e fxerr) Error() string {
|
||||
switch e {
|
||||
case ErrSshFxOk:
|
||||
case ErrSSHFxOk:
|
||||
return "OK"
|
||||
case ErrSshFxEof:
|
||||
case ErrSSHFxEOF:
|
||||
return "EOF"
|
||||
case ErrSshFxNoSuchFile:
|
||||
case ErrSSHFxNoSuchFile:
|
||||
return "No Such File"
|
||||
case ErrSshFxPermissionDenied:
|
||||
case ErrSSHFxPermissionDenied:
|
||||
return "Permission Denied"
|
||||
case ErrSshFxBadMessage:
|
||||
case ErrSSHFxBadMessage:
|
||||
return "Bad Message"
|
||||
case ErrSshFxNoConnection:
|
||||
case ErrSSHFxNoConnection:
|
||||
return "No Connection"
|
||||
case ErrSshFxConnectionLost:
|
||||
case ErrSSHFxConnectionLost:
|
||||
return "Connection Lost"
|
||||
case ErrSshFxOpUnsupported:
|
||||
case ErrSSHFxOpUnsupported:
|
||||
return "Operation Unsupported"
|
||||
default:
|
||||
return "Failure"
|
||||
|
|
|
@ -156,15 +156,15 @@ func (fs *root) Filelist(r *Request) (ListerAt, error) {
|
|||
if !file.IsDir() {
|
||||
return nil, syscall.ENOTDIR
|
||||
}
|
||||
ordered_names := []string{}
|
||||
for fn, _ := range fs.files {
|
||||
orderedNames := []string{}
|
||||
for fn := range fs.files {
|
||||
if filepath.Dir(fn) == r.Filepath {
|
||||
ordered_names = append(ordered_names, fn)
|
||||
orderedNames = append(orderedNames, fn)
|
||||
}
|
||||
}
|
||||
sort.Strings(ordered_names)
|
||||
list := make([]os.FileInfo, len(ordered_names))
|
||||
for i, fn := range ordered_names {
|
||||
sort.Strings(orderedNames)
|
||||
list := make([]os.FileInfo, len(orderedNames))
|
||||
for i, fn := range orderedNames {
|
||||
list[i] = fs.files[fn]
|
||||
}
|
||||
return listerat(list), nil
|
||||
|
|
|
@ -177,7 +177,7 @@ func (rs *RequestServer) packetWorker(
|
|||
case *sshFxpExtendedPacket:
|
||||
switch expkt := pkt.SpecificPacket.(type) {
|
||||
default:
|
||||
rpkt = statusFromError(pkt, ErrSshFxOpUnsupported)
|
||||
rpkt = statusFromError(pkt, ErrSSHFxOpUnsupported)
|
||||
case *sshFxpExtendedPacketPosixRename:
|
||||
request := NewRequest("Rename", expkt.Oldpath)
|
||||
request.Target = expkt.Newpath
|
||||
|
@ -196,11 +196,11 @@ func (rs *RequestServer) packetWorker(
|
|||
rpkt = request.call(rs.Handlers, pkt)
|
||||
request.close()
|
||||
default:
|
||||
rpkt = statusFromError(pkt, ErrSshFxOpUnsupported)
|
||||
rpkt = statusFromError(pkt, ErrSSHFxOpUnsupported)
|
||||
}
|
||||
|
||||
rs.pktMgr.readyPacket(
|
||||
rs.pktMgr.newOrderedResponse(rpkt, pkt.orderId()))
|
||||
rs.pktMgr.newOrderedResponse(rpkt, pkt.orderID()))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -378,7 +378,7 @@ func TestRequestReaddir(t *testing.T) {
|
|||
}
|
||||
}
|
||||
_, err := p.cli.ReadDir("/foo_01")
|
||||
assert.Equal(t, &StatusError{Code: ssh_FX_FAILURE,
|
||||
assert.Equal(t, &StatusError{Code: sshFxFailure,
|
||||
msg: " /foo_01: not a directory"}, err)
|
||||
_, err = p.cli.ReadDir("/does_not_exist")
|
||||
assert.Equal(t, os.ErrNotExist, err)
|
||||
|
|
|
@ -14,10 +14,10 @@ func fakeFileInfoSys() interface{} {
|
|||
func testOsSys(sys interface{}) error {
|
||||
fstat := sys.(*FileStat)
|
||||
if fstat.UID != uint32(65534) {
|
||||
return errors.New("Uid failed to match.")
|
||||
return errors.New("Uid failed to match")
|
||||
}
|
||||
if fstat.GID != uint32(65534) {
|
||||
return errors.New("Gid failed to match:")
|
||||
return errors.New("Gid failed to match")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -65,9 +65,9 @@ func testRequest(method string) *Request {
|
|||
var flags uint32
|
||||
switch method {
|
||||
case "Get":
|
||||
flags = flags | ssh_FXF_READ
|
||||
flags = flags | sshFxfRead
|
||||
case "Put":
|
||||
flags = flags | ssh_FXF_WRITE
|
||||
flags = flags | sshFxfWrite
|
||||
}
|
||||
request := &Request{
|
||||
Filepath: "./request_test.go",
|
||||
|
@ -123,7 +123,7 @@ func getStatusMsg(p interface{}) string {
|
|||
}
|
||||
func checkOkStatus(t *testing.T, p interface{}) {
|
||||
pkt := p.(sshFxpStatusPacket)
|
||||
assert.Equal(t, pkt.StatusError.Code, uint32(ssh_FX_OK),
|
||||
assert.Equal(t, pkt.StatusError.Code, uint32(sshFxOk),
|
||||
"sshFxpStatusPacket not OK\n", pkt.StatusError.msg)
|
||||
}
|
||||
|
||||
|
|
77
server.go
77
server.go
|
@ -18,6 +18,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// SftpServerWorkerCount defines the number of workers for the SFTP server
|
||||
SftpServerWorkerCount = 8
|
||||
)
|
||||
|
||||
|
@ -141,7 +142,7 @@ func (svr *Server) sftpServerWorker(pktChan chan orderedRequest) error {
|
|||
if !readonly && svr.readOnly {
|
||||
svr.sendPacket(orderedResponse{
|
||||
responsePacket: statusFromError(pkt, syscall.EPERM),
|
||||
orderid: pkt.orderId()})
|
||||
orderid: pkt.orderID()})
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -249,7 +250,7 @@ func handlePacket(s *Server, p orderedRequest) error {
|
|||
rpkt = sshFxpOpenPacket{
|
||||
ID: p.ID,
|
||||
Path: p.Path,
|
||||
Pflags: ssh_FXF_READ,
|
||||
Pflags: sshFxfRead,
|
||||
}.respond(s)
|
||||
}
|
||||
case *sshFxpReadPacket:
|
||||
|
@ -281,7 +282,7 @@ func handlePacket(s *Server, p orderedRequest) error {
|
|||
rpkt = statusFromError(p, err)
|
||||
case *sshFxpExtendedPacket:
|
||||
if p.SpecificPacket == nil {
|
||||
rpkt = statusFromError(p, ErrSshFxOpUnsupported)
|
||||
rpkt = statusFromError(p, ErrSSHFxOpUnsupported)
|
||||
} else {
|
||||
rpkt = p.respond(s)
|
||||
}
|
||||
|
@ -291,7 +292,7 @@ func handlePacket(s *Server, p orderedRequest) error {
|
|||
return errors.Errorf("unexpected packet type %T", p)
|
||||
}
|
||||
|
||||
s.pktMgr.readyPacket(s.pktMgr.newOrderedResponse(rpkt, p.orderId()))
|
||||
s.pktMgr.readyPacket(s.pktMgr.newOrderedResponse(rpkt, p.orderID()))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -363,7 +364,7 @@ type sshFxpStatResponse struct {
|
|||
}
|
||||
|
||||
func (p sshFxpStatResponse) MarshalBinary() ([]byte, error) {
|
||||
b := []byte{ssh_FXP_ATTRS}
|
||||
b := []byte{sshFxpAttrs}
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalFileInfo(b, p.info)
|
||||
return b, nil
|
||||
|
@ -372,7 +373,7 @@ func (p sshFxpStatResponse) MarshalBinary() ([]byte, error) {
|
|||
var emptyFileStat = []interface{}{uint32(0)}
|
||||
|
||||
func (p sshFxpOpenPacket) readonly() bool {
|
||||
return !p.hasPflags(ssh_FXF_WRITE)
|
||||
return !p.hasPflags(sshFxfWrite)
|
||||
}
|
||||
|
||||
func (p sshFxpOpenPacket) hasPflags(flags ...uint32) bool {
|
||||
|
@ -386,27 +387,27 @@ func (p sshFxpOpenPacket) hasPflags(flags ...uint32) bool {
|
|||
|
||||
func (p sshFxpOpenPacket) respond(svr *Server) responsePacket {
|
||||
var osFlags int
|
||||
if p.hasPflags(ssh_FXF_READ, ssh_FXF_WRITE) {
|
||||
if p.hasPflags(sshFxfRead, sshFxfWrite) {
|
||||
osFlags |= os.O_RDWR
|
||||
} else if p.hasPflags(ssh_FXF_WRITE) {
|
||||
} else if p.hasPflags(sshFxfWrite) {
|
||||
osFlags |= os.O_WRONLY
|
||||
} else if p.hasPflags(ssh_FXF_READ) {
|
||||
} else if p.hasPflags(sshFxfRead) {
|
||||
osFlags |= os.O_RDONLY
|
||||
} else {
|
||||
// how are they opening?
|
||||
return statusFromError(p, syscall.EINVAL)
|
||||
}
|
||||
|
||||
if p.hasPflags(ssh_FXF_APPEND) {
|
||||
if p.hasPflags(sshFxfAppend) {
|
||||
osFlags |= os.O_APPEND
|
||||
}
|
||||
if p.hasPflags(ssh_FXF_CREAT) {
|
||||
if p.hasPflags(sshFxfCreat) {
|
||||
osFlags |= os.O_CREATE
|
||||
}
|
||||
if p.hasPflags(ssh_FXF_TRUNC) {
|
||||
if p.hasPflags(sshFxfTrunc) {
|
||||
osFlags |= os.O_TRUNC
|
||||
}
|
||||
if p.hasPflags(ssh_FXF_EXCL) {
|
||||
if p.hasPflags(sshFxfExcl) {
|
||||
osFlags |= os.O_EXCL
|
||||
}
|
||||
|
||||
|
@ -448,19 +449,19 @@ func (p sshFxpSetstatPacket) respond(svr *Server) responsePacket {
|
|||
var err error
|
||||
|
||||
debug("setstat name \"%s\"", p.Path)
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_SIZE) != 0 {
|
||||
if (p.Flags & sshFileXferAttrSize) != 0 {
|
||||
var size uint64
|
||||
if size, b, err = unmarshalUint64Safe(b); err == nil {
|
||||
err = os.Truncate(p.Path, int64(size))
|
||||
}
|
||||
}
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_PERMISSIONS) != 0 {
|
||||
if (p.Flags & sshFileXferAttrPermissions) != 0 {
|
||||
var mode uint32
|
||||
if mode, b, err = unmarshalUint32Safe(b); err == nil {
|
||||
err = os.Chmod(p.Path, os.FileMode(mode))
|
||||
}
|
||||
}
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_ACMODTIME) != 0 {
|
||||
if (p.Flags & sshFileXferAttrACmodTime) != 0 {
|
||||
var atime uint32
|
||||
var mtime uint32
|
||||
if atime, b, err = unmarshalUint32Safe(b); err != nil {
|
||||
|
@ -471,7 +472,7 @@ func (p sshFxpSetstatPacket) respond(svr *Server) responsePacket {
|
|||
err = os.Chtimes(p.Path, atimeT, mtimeT)
|
||||
}
|
||||
}
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_UIDGID) != 0 {
|
||||
if (p.Flags & sshFileXferAttrUIDGID) != 0 {
|
||||
var uid uint32
|
||||
var gid uint32
|
||||
if uid, b, err = unmarshalUint32Safe(b); err != nil {
|
||||
|
@ -495,19 +496,19 @@ func (p sshFxpFsetstatPacket) respond(svr *Server) responsePacket {
|
|||
var err error
|
||||
|
||||
debug("fsetstat name \"%s\"", f.Name())
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_SIZE) != 0 {
|
||||
if (p.Flags & sshFileXferAttrSize) != 0 {
|
||||
var size uint64
|
||||
if size, b, err = unmarshalUint64Safe(b); err == nil {
|
||||
err = f.Truncate(int64(size))
|
||||
}
|
||||
}
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_PERMISSIONS) != 0 {
|
||||
if (p.Flags & sshFileXferAttrPermissions) != 0 {
|
||||
var mode uint32
|
||||
if mode, b, err = unmarshalUint32Safe(b); err == nil {
|
||||
err = f.Chmod(os.FileMode(mode))
|
||||
}
|
||||
}
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_ACMODTIME) != 0 {
|
||||
if (p.Flags & sshFileXferAttrACmodTime) != 0 {
|
||||
var atime uint32
|
||||
var mtime uint32
|
||||
if atime, b, err = unmarshalUint32Safe(b); err != nil {
|
||||
|
@ -518,7 +519,7 @@ func (p sshFxpFsetstatPacket) respond(svr *Server) responsePacket {
|
|||
err = os.Chtimes(f.Name(), atimeT, mtimeT)
|
||||
}
|
||||
}
|
||||
if (p.Flags & ssh_FILEXFER_ATTR_UIDGID) != 0 {
|
||||
if (p.Flags & sshFileXferAttrUIDGID) != 0 {
|
||||
var uid uint32
|
||||
var gid uint32
|
||||
if uid, b, err = unmarshalUint32Safe(b); err != nil {
|
||||
|
@ -535,30 +536,30 @@ func (p sshFxpFsetstatPacket) respond(svr *Server) responsePacket {
|
|||
func translateErrno(errno syscall.Errno) uint32 {
|
||||
switch errno {
|
||||
case 0:
|
||||
return ssh_FX_OK
|
||||
return sshFxOk
|
||||
case syscall.ENOENT:
|
||||
return ssh_FX_NO_SUCH_FILE
|
||||
return sshFxNoSuchFile
|
||||
case syscall.EPERM:
|
||||
return ssh_FX_PERMISSION_DENIED
|
||||
return sshFxPermissionDenied
|
||||
}
|
||||
|
||||
return ssh_FX_FAILURE
|
||||
return sshFxFailure
|
||||
}
|
||||
|
||||
func statusFromError(p ider, err error) sshFxpStatusPacket {
|
||||
ret := sshFxpStatusPacket{
|
||||
ID: p.id(),
|
||||
StatusError: StatusError{
|
||||
// ssh_FX_OK = 0
|
||||
// ssh_FX_EOF = 1
|
||||
// ssh_FX_NO_SUCH_FILE = 2 ENOENT
|
||||
// ssh_FX_PERMISSION_DENIED = 3
|
||||
// ssh_FX_FAILURE = 4
|
||||
// ssh_FX_BAD_MESSAGE = 5
|
||||
// ssh_FX_NO_CONNECTION = 6
|
||||
// ssh_FX_CONNECTION_LOST = 7
|
||||
// ssh_FX_OP_UNSUPPORTED = 8
|
||||
Code: ssh_FX_OK,
|
||||
// sshFXOk = 0
|
||||
// sshFXEOF = 1
|
||||
// sshFXNoSuchFile = 2 ENOENT
|
||||
// sshFXPermissionDenied = 3
|
||||
// sshFXFailure = 4
|
||||
// sshFXBadMessage = 5
|
||||
// sshFXNoConnection = 6
|
||||
// sshFXConnectionLost = 7
|
||||
// sshFXOPUnsupported = 8
|
||||
Code: sshFxOk,
|
||||
},
|
||||
}
|
||||
if err == nil {
|
||||
|
@ -566,7 +567,7 @@ func statusFromError(p ider, err error) sshFxpStatusPacket {
|
|||
}
|
||||
|
||||
debug("statusFromError: error is %T %#v", err, err)
|
||||
ret.StatusError.Code = ssh_FX_FAILURE
|
||||
ret.StatusError.Code = sshFxFailure
|
||||
ret.StatusError.msg = err.Error()
|
||||
|
||||
switch e := err.(type) {
|
||||
|
@ -582,9 +583,9 @@ func statusFromError(p ider, err error) sshFxpStatusPacket {
|
|||
default:
|
||||
switch e {
|
||||
case io.EOF:
|
||||
ret.StatusError.Code = ssh_FX_EOF
|
||||
ret.StatusError.Code = sshFxEOF
|
||||
case os.ErrNotExist:
|
||||
ret.StatusError.Code = ssh_FX_NO_SUCH_FILE
|
||||
ret.StatusError.Code = sshFxNoSuchFile
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ var sftpServerDebugStream = ioutil.Discard
|
|||
var sftpClientDebugStream = ioutil.Discard
|
||||
|
||||
const (
|
||||
GOLANG_SFTP = true
|
||||
OPENSSH_SFTP = false
|
||||
GolangSFTP = true
|
||||
OpenSSHSFTP = false
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -468,8 +468,8 @@ func runSftpClient(t *testing.T, script string, path string, host string, port i
|
|||
}
|
||||
|
||||
func TestServerCompareSubsystems(t *testing.T) {
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerOp, hostOp, portOp := testServer(t, OPENSSH_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
listenerOp, hostOp, portOp := testServer(t, OpenSSHSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
defer listenerOp.Close()
|
||||
|
||||
|
@ -543,7 +543,7 @@ func randName() string {
|
|||
}
|
||||
|
||||
func TestServerMkdirRmdir(t *testing.T) {
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
tmpDir := "/tmp/" + randName()
|
||||
|
@ -571,7 +571,7 @@ func TestServerMkdirRmdir(t *testing.T) {
|
|||
|
||||
func TestServerLink(t *testing.T) {
|
||||
skipIfWindows(t) // No hard links on windows.
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
tmpFileLocalData := randData(999)
|
||||
|
@ -600,7 +600,7 @@ func TestServerLink(t *testing.T) {
|
|||
|
||||
func TestServerSymlink(t *testing.T) {
|
||||
skipIfWindows(t) // No symlinks on windows.
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
link := "/tmp/" + randName()
|
||||
|
@ -620,7 +620,7 @@ func TestServerSymlink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServerPut(t *testing.T) {
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
tmpFileLocal := "/tmp/" + randName()
|
||||
|
@ -650,7 +650,7 @@ func TestServerPut(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServerGet(t *testing.T) {
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
tmpFileLocal := "/tmp/" + randName()
|
||||
|
@ -746,7 +746,7 @@ func compareDirectoriesRecursive(t *testing.T, aroot, broot string) {
|
|||
}
|
||||
|
||||
func TestServerPutRecursive(t *testing.T) {
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
dirLocal, err := os.Getwd()
|
||||
|
@ -767,7 +767,7 @@ func TestServerPutRecursive(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServerGetRecursive(t *testing.T) {
|
||||
listenerGo, hostGo, portGo := testServer(t, GOLANG_SFTP, READONLY)
|
||||
listenerGo, hostGo, portGo := testServer(t, GolangSFTP, READONLY)
|
||||
defer listenerGo.Close()
|
||||
|
||||
dirRemote, err := os.Getwd()
|
||||
|
|
|
@ -191,7 +191,7 @@ func (p sshFxpTestBadExtendedPacket) MarshalBinary() ([]byte, error) {
|
|||
len(p.Data)
|
||||
|
||||
b := make([]byte, 0, l)
|
||||
b = append(b, ssh_FXP_EXTENDED)
|
||||
b = append(b, sshFxpExtended)
|
||||
b = marshalUint32(b, p.ID)
|
||||
b = marshalString(b, p.Extension)
|
||||
b = marshalString(b, p.Data)
|
||||
|
@ -210,7 +210,7 @@ func TestInvalidExtendedPacket(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected error from sendPacket: %s", err)
|
||||
}
|
||||
if typ != ssh_FXP_STATUS {
|
||||
if typ != sshFxpStatus {
|
||||
t.Fatalf("received non-FPX_STATUS packet: %v", typ)
|
||||
}
|
||||
|
||||
|
@ -219,8 +219,8 @@ func TestInvalidExtendedPacket(t *testing.T) {
|
|||
if !ok {
|
||||
t.Fatal("failed to convert error from unmarshalStatus to *StatusError")
|
||||
}
|
||||
if statusErr.Code != ssh_FX_OP_UNSUPPORTED {
|
||||
t.Errorf("statusErr.Code => %d, wanted %d", statusErr.Code, ssh_FX_OP_UNSUPPORTED)
|
||||
if statusErr.Code != sshFxOPUnsupported {
|
||||
t.Errorf("statusErr.Code => %d, wanted %d", statusErr.Code, sshFxOPUnsupported)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,17 +265,17 @@ func TestStatusFromError(t *testing.T) {
|
|||
StatusError: StatusError{Code: code},
|
||||
}
|
||||
}
|
||||
test_cases := []test{
|
||||
test{syscall.ENOENT, tpkt(1, ssh_FX_NO_SUCH_FILE)},
|
||||
testCases := []test{
|
||||
test{syscall.ENOENT, tpkt(1, sshFxNoSuchFile)},
|
||||
test{&os.PathError{Err: syscall.ENOENT},
|
||||
tpkt(2, ssh_FX_NO_SUCH_FILE)},
|
||||
test{&os.PathError{Err: errors.New("foo")}, tpkt(3, ssh_FX_FAILURE)},
|
||||
test{ErrSshFxEof, tpkt(4, ssh_FX_EOF)},
|
||||
test{ErrSshFxOpUnsupported, tpkt(5, ssh_FX_OP_UNSUPPORTED)},
|
||||
test{io.EOF, tpkt(6, ssh_FX_EOF)},
|
||||
test{os.ErrNotExist, tpkt(7, ssh_FX_NO_SUCH_FILE)},
|
||||
tpkt(2, sshFxNoSuchFile)},
|
||||
test{&os.PathError{Err: errors.New("foo")}, tpkt(3, sshFxFailure)},
|
||||
test{ErrSSHFxEOF, tpkt(4, sshFxEOF)},
|
||||
test{ErrSSHFxOpUnsupported, tpkt(5, sshFxOPUnsupported)},
|
||||
test{io.EOF, tpkt(6, sshFxEOF)},
|
||||
test{os.ErrNotExist, tpkt(7, sshFxNoSuchFile)},
|
||||
}
|
||||
for _, tc := range test_cases {
|
||||
for _, tc := range testCases {
|
||||
tc.pkt.StatusError.msg = tc.err.Error()
|
||||
assert.Equal(t, tc.pkt, statusFromError(tc.pkt, tc.err))
|
||||
}
|
||||
|
@ -316,8 +316,8 @@ func TestOpenStatRace(t *testing.T) {
|
|||
testreply := func(id uint32, ch chan result) {
|
||||
r := <-ch
|
||||
switch r.typ {
|
||||
case ssh_FXP_ATTRS, ssh_FXP_HANDLE: // ignore
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpAttrs, sshFxpHandle: // ignore
|
||||
case sshFxpStatus:
|
||||
err := normaliseError(unmarshalStatus(id, r.data))
|
||||
assert.NoError(t, err, "race hit, stat before open")
|
||||
default:
|
||||
|
|
202
sftp.go
202
sftp.go
|
@ -9,80 +9,80 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
ssh_FXP_INIT = 1
|
||||
ssh_FXP_VERSION = 2
|
||||
ssh_FXP_OPEN = 3
|
||||
ssh_FXP_CLOSE = 4
|
||||
ssh_FXP_READ = 5
|
||||
ssh_FXP_WRITE = 6
|
||||
ssh_FXP_LSTAT = 7
|
||||
ssh_FXP_FSTAT = 8
|
||||
ssh_FXP_SETSTAT = 9
|
||||
ssh_FXP_FSETSTAT = 10
|
||||
ssh_FXP_OPENDIR = 11
|
||||
ssh_FXP_READDIR = 12
|
||||
ssh_FXP_REMOVE = 13
|
||||
ssh_FXP_MKDIR = 14
|
||||
ssh_FXP_RMDIR = 15
|
||||
ssh_FXP_REALPATH = 16
|
||||
ssh_FXP_STAT = 17
|
||||
ssh_FXP_RENAME = 18
|
||||
ssh_FXP_READLINK = 19
|
||||
ssh_FXP_SYMLINK = 20
|
||||
ssh_FXP_STATUS = 101
|
||||
ssh_FXP_HANDLE = 102
|
||||
ssh_FXP_DATA = 103
|
||||
ssh_FXP_NAME = 104
|
||||
ssh_FXP_ATTRS = 105
|
||||
ssh_FXP_EXTENDED = 200
|
||||
ssh_FXP_EXTENDED_REPLY = 201
|
||||
sshFxpInit = 1
|
||||
sshFxpVersion = 2
|
||||
sshFxpOpen = 3
|
||||
sshFxpClose = 4
|
||||
sshFxpRead = 5
|
||||
sshFxpWrite = 6
|
||||
sshFxpLstat = 7
|
||||
sshFxpFstat = 8
|
||||
sshFxpSetstat = 9
|
||||
sshFxpFsetstat = 10
|
||||
sshFxpOpendir = 11
|
||||
sshFxpReaddir = 12
|
||||
sshFxpRemove = 13
|
||||
sshFxpMkdir = 14
|
||||
sshFxpRmdir = 15
|
||||
sshFxpRealpath = 16
|
||||
sshFxpStat = 17
|
||||
sshFxpRename = 18
|
||||
sshFxpReadlink = 19
|
||||
sshFxpSymlink = 20
|
||||
sshFxpStatus = 101
|
||||
sshFxpHandle = 102
|
||||
sshFxpData = 103
|
||||
sshFxpName = 104
|
||||
sshFxpAttrs = 105
|
||||
sshFxpExtended = 200
|
||||
sshFxpExtendedReply = 201
|
||||
)
|
||||
|
||||
const (
|
||||
ssh_FX_OK = 0
|
||||
ssh_FX_EOF = 1
|
||||
ssh_FX_NO_SUCH_FILE = 2
|
||||
ssh_FX_PERMISSION_DENIED = 3
|
||||
ssh_FX_FAILURE = 4
|
||||
ssh_FX_BAD_MESSAGE = 5
|
||||
ssh_FX_NO_CONNECTION = 6
|
||||
ssh_FX_CONNECTION_LOST = 7
|
||||
ssh_FX_OP_UNSUPPORTED = 8
|
||||
sshFxOk = 0
|
||||
sshFxEOF = 1
|
||||
sshFxNoSuchFile = 2
|
||||
sshFxPermissionDenied = 3
|
||||
sshFxFailure = 4
|
||||
sshFxBadMessage = 5
|
||||
sshFxNoConnection = 6
|
||||
sshFxConnectionLost = 7
|
||||
sshFxOPUnsupported = 8
|
||||
|
||||
// see draft-ietf-secsh-filexfer-13
|
||||
// https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1
|
||||
ssh_FX_INVALID_HANDLE = 9
|
||||
ssh_FX_NO_SUCH_PATH = 10
|
||||
ssh_FX_FILE_ALREADY_EXISTS = 11
|
||||
ssh_FX_WRITE_PROTECT = 12
|
||||
ssh_FX_NO_MEDIA = 13
|
||||
ssh_FX_NO_SPACE_ON_FILESYSTEM = 14
|
||||
ssh_FX_QUOTA_EXCEEDED = 15
|
||||
ssh_FX_UNKNOWN_PRINCIPAL = 16
|
||||
ssh_FX_LOCK_CONFLICT = 17
|
||||
ssh_FX_DIR_NOT_EMPTY = 18
|
||||
ssh_FX_NOT_A_DIRECTORY = 19
|
||||
ssh_FX_INVALID_FILENAME = 20
|
||||
ssh_FX_LINK_LOOP = 21
|
||||
ssh_FX_CANNOT_DELETE = 22
|
||||
ssh_FX_INVALID_PARAMETER = 23
|
||||
ssh_FX_FILE_IS_A_DIRECTORY = 24
|
||||
ssh_FX_BYTE_RANGE_LOCK_CONFLICT = 25
|
||||
ssh_FX_BYTE_RANGE_LOCK_REFUSED = 26
|
||||
ssh_FX_DELETE_PENDING = 27
|
||||
ssh_FX_FILE_CORRUPT = 28
|
||||
ssh_FX_OWNER_INVALID = 29
|
||||
ssh_FX_GROUP_INVALID = 30
|
||||
ssh_FX_NO_MATCHING_BYTE_RANGE_LOCK = 31
|
||||
sshFxInvalidHandle = 9
|
||||
sshFxNoSuchPath = 10
|
||||
sshFxFileAlreadyExists = 11
|
||||
sshFxWriteProtect = 12
|
||||
sshFxNoMedia = 13
|
||||
sshFxNoSpaceOnFilesystem = 14
|
||||
sshFxQuotaExceeded = 15
|
||||
sshFxUnlnownPrincipal = 16
|
||||
sshFxLockConflict = 17
|
||||
sshFxDitNotEmpty = 18
|
||||
sshFxNotADirectory = 19
|
||||
sshFxInvalidFilename = 20
|
||||
sshFxLinkLoop = 21
|
||||
sshFxCannotDelete = 22
|
||||
sshFxInvalidParameter = 23
|
||||
sshFxFileIsADirectory = 24
|
||||
sshFxByteRangeLockConflict = 25
|
||||
sshFxByteRangeLockRefused = 26
|
||||
sshFxDeletePending = 27
|
||||
sshFxFileCorrupt = 28
|
||||
sshFxOwnerInvalid = 29
|
||||
sshFxGroupInvalid = 30
|
||||
sshFxNoMatchingByteRangeLock = 31
|
||||
)
|
||||
|
||||
const (
|
||||
ssh_FXF_READ = 0x00000001
|
||||
ssh_FXF_WRITE = 0x00000002
|
||||
ssh_FXF_APPEND = 0x00000004
|
||||
ssh_FXF_CREAT = 0x00000008
|
||||
ssh_FXF_TRUNC = 0x00000010
|
||||
ssh_FXF_EXCL = 0x00000020
|
||||
sshFxfRead = 0x00000001
|
||||
sshFxfWrite = 0x00000002
|
||||
sshFxfAppend = 0x00000004
|
||||
sshFxfCreat = 0x00000008
|
||||
sshFxfTrunc = 0x00000010
|
||||
sshFxfExcl = 0x00000020
|
||||
)
|
||||
|
||||
var sftpExtensions = []sshExtensionPair{
|
||||
|
@ -94,59 +94,59 @@ type fxp uint8
|
|||
|
||||
func (f fxp) String() string {
|
||||
switch f {
|
||||
case ssh_FXP_INIT:
|
||||
case sshFxpInit:
|
||||
return "SSH_FXP_INIT"
|
||||
case ssh_FXP_VERSION:
|
||||
case sshFxpVersion:
|
||||
return "SSH_FXP_VERSION"
|
||||
case ssh_FXP_OPEN:
|
||||
case sshFxpOpen:
|
||||
return "SSH_FXP_OPEN"
|
||||
case ssh_FXP_CLOSE:
|
||||
case sshFxpClose:
|
||||
return "SSH_FXP_CLOSE"
|
||||
case ssh_FXP_READ:
|
||||
case sshFxpRead:
|
||||
return "SSH_FXP_READ"
|
||||
case ssh_FXP_WRITE:
|
||||
case sshFxpWrite:
|
||||
return "SSH_FXP_WRITE"
|
||||
case ssh_FXP_LSTAT:
|
||||
case sshFxpLstat:
|
||||
return "SSH_FXP_LSTAT"
|
||||
case ssh_FXP_FSTAT:
|
||||
case sshFxpFstat:
|
||||
return "SSH_FXP_FSTAT"
|
||||
case ssh_FXP_SETSTAT:
|
||||
case sshFxpSetstat:
|
||||
return "SSH_FXP_SETSTAT"
|
||||
case ssh_FXP_FSETSTAT:
|
||||
case sshFxpFsetstat:
|
||||
return "SSH_FXP_FSETSTAT"
|
||||
case ssh_FXP_OPENDIR:
|
||||
case sshFxpOpendir:
|
||||
return "SSH_FXP_OPENDIR"
|
||||
case ssh_FXP_READDIR:
|
||||
case sshFxpReaddir:
|
||||
return "SSH_FXP_READDIR"
|
||||
case ssh_FXP_REMOVE:
|
||||
case sshFxpRemove:
|
||||
return "SSH_FXP_REMOVE"
|
||||
case ssh_FXP_MKDIR:
|
||||
case sshFxpMkdir:
|
||||
return "SSH_FXP_MKDIR"
|
||||
case ssh_FXP_RMDIR:
|
||||
case sshFxpRmdir:
|
||||
return "SSH_FXP_RMDIR"
|
||||
case ssh_FXP_REALPATH:
|
||||
case sshFxpRealpath:
|
||||
return "SSH_FXP_REALPATH"
|
||||
case ssh_FXP_STAT:
|
||||
case sshFxpStat:
|
||||
return "SSH_FXP_STAT"
|
||||
case ssh_FXP_RENAME:
|
||||
case sshFxpRename:
|
||||
return "SSH_FXP_RENAME"
|
||||
case ssh_FXP_READLINK:
|
||||
case sshFxpReadlink:
|
||||
return "SSH_FXP_READLINK"
|
||||
case ssh_FXP_SYMLINK:
|
||||
case sshFxpSymlink:
|
||||
return "SSH_FXP_SYMLINK"
|
||||
case ssh_FXP_STATUS:
|
||||
case sshFxpStatus:
|
||||
return "SSH_FXP_STATUS"
|
||||
case ssh_FXP_HANDLE:
|
||||
case sshFxpHandle:
|
||||
return "SSH_FXP_HANDLE"
|
||||
case ssh_FXP_DATA:
|
||||
case sshFxpData:
|
||||
return "SSH_FXP_DATA"
|
||||
case ssh_FXP_NAME:
|
||||
case sshFxpName:
|
||||
return "SSH_FXP_NAME"
|
||||
case ssh_FXP_ATTRS:
|
||||
case sshFxpAttrs:
|
||||
return "SSH_FXP_ATTRS"
|
||||
case ssh_FXP_EXTENDED:
|
||||
case sshFxpExtended:
|
||||
return "SSH_FXP_EXTENDED"
|
||||
case ssh_FXP_EXTENDED_REPLY:
|
||||
case sshFxpExtendedReply:
|
||||
return "SSH_FXP_EXTENDED_REPLY"
|
||||
default:
|
||||
return "unknown"
|
||||
|
@ -157,23 +157,23 @@ type fx uint8
|
|||
|
||||
func (f fx) String() string {
|
||||
switch f {
|
||||
case ssh_FX_OK:
|
||||
case sshFxOk:
|
||||
return "SSH_FX_OK"
|
||||
case ssh_FX_EOF:
|
||||
case sshFxEOF:
|
||||
return "SSH_FX_EOF"
|
||||
case ssh_FX_NO_SUCH_FILE:
|
||||
case sshFxNoSuchFile:
|
||||
return "SSH_FX_NO_SUCH_FILE"
|
||||
case ssh_FX_PERMISSION_DENIED:
|
||||
case sshFxPermissionDenied:
|
||||
return "SSH_FX_PERMISSION_DENIED"
|
||||
case ssh_FX_FAILURE:
|
||||
case sshFxFailure:
|
||||
return "SSH_FX_FAILURE"
|
||||
case ssh_FX_BAD_MESSAGE:
|
||||
case sshFxBadMessage:
|
||||
return "SSH_FX_BAD_MESSAGE"
|
||||
case ssh_FX_NO_CONNECTION:
|
||||
case sshFxNoConnection:
|
||||
return "SSH_FX_NO_CONNECTION"
|
||||
case ssh_FX_CONNECTION_LOST:
|
||||
case sshFxConnectionLost:
|
||||
return "SSH_FX_CONNECTION_LOST"
|
||||
case ssh_FX_OP_UNSUPPORTED:
|
||||
case sshFxOPUnsupported:
|
||||
return "SSH_FX_OP_UNSUPPORTED"
|
||||
default:
|
||||
return "unknown"
|
||||
|
|
Loading…
Reference in New Issue