mirror of https://github.com/pkg/sftp.git
rename sendRequest to sendPacket
clientConn.sendPacket now obscures clientConn.conn.sendPacket with a diferent signature.
This commit is contained in:
parent
0847713e96
commit
1a25dc501f
34
client.go
34
client.go
|
@ -102,7 +102,7 @@ func (c *Client) Create(path string) (*File, error) {
|
||||||
const sftpProtocolVersion = 3 // http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
|
const sftpProtocolVersion = 3 // http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
|
||||||
|
|
||||||
func (c *Client) sendInit() error {
|
func (c *Client) sendInit() error {
|
||||||
return c.sendPacket(sshFxInitPacket{
|
return c.clientConn.conn.sendPacket(sshFxInitPacket{
|
||||||
Version: sftpProtocolVersion, // http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
|
Version: sftpProtocolVersion, // http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func (c *Client) ReadDir(p string) ([]os.FileInfo, error) {
|
||||||
var done = false
|
var done = false
|
||||||
for !done {
|
for !done {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err1 := c.sendRequest(sshFxpReaddirPacket{
|
typ, data, err1 := c.sendPacket(sshFxpReaddirPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Handle: handle,
|
Handle: handle,
|
||||||
})
|
})
|
||||||
|
@ -189,7 +189,7 @@ func (c *Client) ReadDir(p string) ([]os.FileInfo, error) {
|
||||||
|
|
||||||
func (c *Client) opendir(path string) (string, error) {
|
func (c *Client) opendir(path string) (string, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpOpendirPacket{
|
typ, data, err := c.sendPacket(sshFxpOpendirPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
})
|
})
|
||||||
|
@ -215,7 +215,7 @@ func (c *Client) opendir(path string) (string, error) {
|
||||||
// If 'p' is a symbolic link, the returned FileInfo structure describes the referent file.
|
// If 'p' is a symbolic link, the returned FileInfo structure describes the referent file.
|
||||||
func (c *Client) Stat(p string) (os.FileInfo, error) {
|
func (c *Client) Stat(p string) (os.FileInfo, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpStatPacket{
|
typ, data, err := c.sendPacket(sshFxpStatPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: p,
|
Path: p,
|
||||||
})
|
})
|
||||||
|
@ -241,7 +241,7 @@ func (c *Client) Stat(p string) (os.FileInfo, error) {
|
||||||
// If 'p' is a symbolic link, the returned FileInfo structure describes the symbolic link.
|
// If 'p' is a symbolic link, the returned FileInfo structure describes the symbolic link.
|
||||||
func (c *Client) Lstat(p string) (os.FileInfo, error) {
|
func (c *Client) Lstat(p string) (os.FileInfo, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpLstatPacket{
|
typ, data, err := c.sendPacket(sshFxpLstatPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: p,
|
Path: p,
|
||||||
})
|
})
|
||||||
|
@ -266,7 +266,7 @@ func (c *Client) Lstat(p string) (os.FileInfo, error) {
|
||||||
// ReadLink reads the target of a symbolic link.
|
// ReadLink reads the target of a symbolic link.
|
||||||
func (c *Client) ReadLink(p string) (string, error) {
|
func (c *Client) ReadLink(p string) (string, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpReadlinkPacket{
|
typ, data, err := c.sendPacket(sshFxpReadlinkPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: p,
|
Path: p,
|
||||||
})
|
})
|
||||||
|
@ -295,7 +295,7 @@ func (c *Client) ReadLink(p string) (string, error) {
|
||||||
// Symlink creates a symbolic link at 'newname', pointing at target 'oldname'
|
// Symlink creates a symbolic link at 'newname', pointing at target 'oldname'
|
||||||
func (c *Client) Symlink(oldname, newname string) error {
|
func (c *Client) Symlink(oldname, newname string) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpSymlinkPacket{
|
typ, data, err := c.sendPacket(sshFxpSymlinkPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Linkpath: newname,
|
Linkpath: newname,
|
||||||
Targetpath: oldname,
|
Targetpath: oldname,
|
||||||
|
@ -314,7 +314,7 @@ func (c *Client) Symlink(oldname, newname string) error {
|
||||||
// setstat is a convience wrapper to allow for changing of various parts of the file descriptor.
|
// setstat is a convience wrapper to allow for changing of various parts of the file descriptor.
|
||||||
func (c *Client) setstat(path string, flags uint32, attrs interface{}) error {
|
func (c *Client) setstat(path string, flags uint32, attrs interface{}) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpSetstatPacket{
|
typ, data, err := c.sendPacket(sshFxpSetstatPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
Flags: flags,
|
Flags: flags,
|
||||||
|
@ -380,7 +380,7 @@ func (c *Client) OpenFile(path string, f int) (*File, error) {
|
||||||
|
|
||||||
func (c *Client) open(path string, pflags uint32) (*File, error) {
|
func (c *Client) open(path string, pflags uint32) (*File, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpOpenPacket{
|
typ, data, err := c.sendPacket(sshFxpOpenPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
Pflags: pflags,
|
Pflags: pflags,
|
||||||
|
@ -408,7 +408,7 @@ func (c *Client) open(path string, pflags uint32) (*File, error) {
|
||||||
// immediately after this request has been sent.
|
// immediately after this request has been sent.
|
||||||
func (c *Client) close(handle string) error {
|
func (c *Client) close(handle string) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpClosePacket{
|
typ, data, err := c.sendPacket(sshFxpClosePacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Handle: handle,
|
Handle: handle,
|
||||||
})
|
})
|
||||||
|
@ -425,7 +425,7 @@ func (c *Client) close(handle string) error {
|
||||||
|
|
||||||
func (c *Client) fstat(handle string) (*FileStat, error) {
|
func (c *Client) fstat(handle string) (*FileStat, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpFstatPacket{
|
typ, data, err := c.sendPacket(sshFxpFstatPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Handle: handle,
|
Handle: handle,
|
||||||
})
|
})
|
||||||
|
@ -454,7 +454,7 @@ func (c *Client) fstat(handle string) (*FileStat, error) {
|
||||||
func (c *Client) StatVFS(path string) (*StatVFS, error) {
|
func (c *Client) StatVFS(path string) (*StatVFS, error) {
|
||||||
// send the StatVFS packet to the server
|
// send the StatVFS packet to the server
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpStatvfsPacket{
|
typ, data, err := c.sendPacket(sshFxpStatvfsPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
})
|
})
|
||||||
|
@ -510,7 +510,7 @@ func (c *Client) Remove(path string) error {
|
||||||
|
|
||||||
func (c *Client) removeFile(path string) error {
|
func (c *Client) removeFile(path string) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpRemovePacket{
|
typ, data, err := c.sendPacket(sshFxpRemovePacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Filename: path,
|
Filename: path,
|
||||||
})
|
})
|
||||||
|
@ -527,7 +527,7 @@ func (c *Client) removeFile(path string) error {
|
||||||
|
|
||||||
func (c *Client) removeDirectory(path string) error {
|
func (c *Client) removeDirectory(path string) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpRmdirPacket{
|
typ, data, err := c.sendPacket(sshFxpRmdirPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
})
|
})
|
||||||
|
@ -545,7 +545,7 @@ func (c *Client) removeDirectory(path string) error {
|
||||||
// Rename renames a file.
|
// Rename renames a file.
|
||||||
func (c *Client) Rename(oldname, newname string) error {
|
func (c *Client) Rename(oldname, newname string) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpRenamePacket{
|
typ, data, err := c.sendPacket(sshFxpRenamePacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Oldpath: oldname,
|
Oldpath: oldname,
|
||||||
Newpath: newname,
|
Newpath: newname,
|
||||||
|
@ -563,7 +563,7 @@ func (c *Client) Rename(oldname, newname string) error {
|
||||||
|
|
||||||
func (c *Client) realpath(path string) (string, error) {
|
func (c *Client) realpath(path string) (string, error) {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpRealpathPacket{
|
typ, data, err := c.sendPacket(sshFxpRealpathPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
})
|
})
|
||||||
|
@ -600,7 +600,7 @@ func (c *Client) Getwd() (string, error) {
|
||||||
// parent folder does not exist (the method cannot create complete paths).
|
// parent folder does not exist (the method cannot create complete paths).
|
||||||
func (c *Client) Mkdir(path string) error {
|
func (c *Client) Mkdir(path string) error {
|
||||||
id := c.nextID()
|
id := c.nextID()
|
||||||
typ, data, err := c.sendRequest(sshFxpMkdirPacket{
|
typ, data, err := c.sendPacket(sshFxpMkdirPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Path: path,
|
Path: path,
|
||||||
})
|
})
|
||||||
|
|
4
conn.go
4
conn.go
|
@ -83,7 +83,7 @@ type idmarshaler interface {
|
||||||
encoding.BinaryMarshaler
|
encoding.BinaryMarshaler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientConn) sendRequest(p idmarshaler) (byte, []byte, error) {
|
func (c *clientConn) sendPacket(p idmarshaler) (byte, []byte, error) {
|
||||||
ch := make(chan result, 1)
|
ch := make(chan result, 1)
|
||||||
c.dispatchRequest(ch, p)
|
c.dispatchRequest(ch, p)
|
||||||
s := <-ch
|
s := <-ch
|
||||||
|
@ -93,7 +93,7 @@ func (c *clientConn) sendRequest(p idmarshaler) (byte, []byte, error) {
|
||||||
func (c *clientConn) dispatchRequest(ch chan<- result, p idmarshaler) {
|
func (c *clientConn) dispatchRequest(ch chan<- result, p idmarshaler) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
c.inflight[p.id()] = ch
|
c.inflight[p.id()] = ch
|
||||||
if err := c.sendPacket(p); err != nil {
|
if err := c.conn.sendPacket(p); err != nil {
|
||||||
delete(c.inflight, p.id())
|
delete(c.inflight, p.id())
|
||||||
ch <- result{err: err}
|
ch <- result{err: err}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func TestInvalidExtendedPacket(t *testing.T) {
|
||||||
client, _ := clientServerPair(t)
|
client, _ := clientServerPair(t)
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
badPacket := sshFxpTestBadExtendedPacket{client.nextID(), "thisDoesn'tExist", "foobar"}
|
badPacket := sshFxpTestBadExtendedPacket{client.nextID(), "thisDoesn'tExist", "foobar"}
|
||||||
_, _, err := client.sendRequest(badPacket)
|
_, _, err := client.clientConn.sendPacket(badPacket)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error from bad packet")
|
t.Fatal("expected error from bad packet")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue