From 1a25dc501f1c21a5b87892404749e7053f70fca0 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Wed, 15 Jun 2016 18:57:05 +1000 Subject: [PATCH] rename sendRequest to sendPacket clientConn.sendPacket now obscures clientConn.conn.sendPacket with a diferent signature. --- client.go | 34 +++++++++++++++++----------------- conn.go | 4 ++-- server_test.go | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/client.go b/client.go index d1967c3..5033827 100644 --- a/client.go +++ b/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 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 }) } @@ -146,7 +146,7 @@ func (c *Client) ReadDir(p string) ([]os.FileInfo, error) { var done = false for !done { id := c.nextID() - typ, data, err1 := c.sendRequest(sshFxpReaddirPacket{ + typ, data, err1 := c.sendPacket(sshFxpReaddirPacket{ ID: id, Handle: handle, }) @@ -189,7 +189,7 @@ func (c *Client) ReadDir(p string) ([]os.FileInfo, error) { func (c *Client) opendir(path string) (string, error) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpOpendirPacket{ + typ, data, err := c.sendPacket(sshFxpOpendirPacket{ ID: id, 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. func (c *Client) Stat(p string) (os.FileInfo, error) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpStatPacket{ + typ, data, err := c.sendPacket(sshFxpStatPacket{ ID: id, 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. func (c *Client) Lstat(p string) (os.FileInfo, error) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpLstatPacket{ + typ, data, err := c.sendPacket(sshFxpLstatPacket{ ID: id, Path: p, }) @@ -266,7 +266,7 @@ func (c *Client) Lstat(p string) (os.FileInfo, error) { // ReadLink reads the target of a symbolic link. func (c *Client) ReadLink(p string) (string, error) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpReadlinkPacket{ + typ, data, err := c.sendPacket(sshFxpReadlinkPacket{ ID: id, 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' func (c *Client) Symlink(oldname, newname string) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpSymlinkPacket{ + typ, data, err := c.sendPacket(sshFxpSymlinkPacket{ ID: id, Linkpath: newname, 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. func (c *Client) setstat(path string, flags uint32, attrs interface{}) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpSetstatPacket{ + typ, data, err := c.sendPacket(sshFxpSetstatPacket{ ID: id, Path: path, 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) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpOpenPacket{ + typ, data, err := c.sendPacket(sshFxpOpenPacket{ ID: id, Path: path, Pflags: pflags, @@ -408,7 +408,7 @@ func (c *Client) open(path string, pflags uint32) (*File, error) { // immediately after this request has been sent. func (c *Client) close(handle string) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpClosePacket{ + typ, data, err := c.sendPacket(sshFxpClosePacket{ ID: id, Handle: handle, }) @@ -425,7 +425,7 @@ func (c *Client) close(handle string) error { func (c *Client) fstat(handle string) (*FileStat, error) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpFstatPacket{ + typ, data, err := c.sendPacket(sshFxpFstatPacket{ ID: id, Handle: handle, }) @@ -454,7 +454,7 @@ func (c *Client) fstat(handle string) (*FileStat, error) { func (c *Client) StatVFS(path string) (*StatVFS, error) { // send the StatVFS packet to the server id := c.nextID() - typ, data, err := c.sendRequest(sshFxpStatvfsPacket{ + typ, data, err := c.sendPacket(sshFxpStatvfsPacket{ ID: id, Path: path, }) @@ -510,7 +510,7 @@ func (c *Client) Remove(path string) error { func (c *Client) removeFile(path string) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpRemovePacket{ + typ, data, err := c.sendPacket(sshFxpRemovePacket{ ID: id, Filename: path, }) @@ -527,7 +527,7 @@ func (c *Client) removeFile(path string) error { func (c *Client) removeDirectory(path string) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpRmdirPacket{ + typ, data, err := c.sendPacket(sshFxpRmdirPacket{ ID: id, Path: path, }) @@ -545,7 +545,7 @@ func (c *Client) removeDirectory(path string) error { // Rename renames a file. func (c *Client) Rename(oldname, newname string) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpRenamePacket{ + typ, data, err := c.sendPacket(sshFxpRenamePacket{ ID: id, Oldpath: oldname, Newpath: newname, @@ -563,7 +563,7 @@ func (c *Client) Rename(oldname, newname string) error { func (c *Client) realpath(path string) (string, error) { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpRealpathPacket{ + typ, data, err := c.sendPacket(sshFxpRealpathPacket{ ID: id, Path: path, }) @@ -600,7 +600,7 @@ func (c *Client) Getwd() (string, error) { // parent folder does not exist (the method cannot create complete paths). func (c *Client) Mkdir(path string) error { id := c.nextID() - typ, data, err := c.sendRequest(sshFxpMkdirPacket{ + typ, data, err := c.sendPacket(sshFxpMkdirPacket{ ID: id, Path: path, }) diff --git a/conn.go b/conn.go index 8899246..1839dfb 100644 --- a/conn.go +++ b/conn.go @@ -83,7 +83,7 @@ type idmarshaler interface { 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) c.dispatchRequest(ch, p) s := <-ch @@ -93,7 +93,7 @@ func (c *clientConn) sendRequest(p idmarshaler) (byte, []byte, error) { func (c *clientConn) dispatchRequest(ch chan<- result, p idmarshaler) { c.Lock() 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()) ch <- result{err: err} } diff --git a/server_test.go b/server_test.go index 7dac703..55825fd 100644 --- a/server_test.go +++ b/server_test.go @@ -42,7 +42,7 @@ func TestInvalidExtendedPacket(t *testing.T) { client, _ := clientServerPair(t) defer client.Close() badPacket := sshFxpTestBadExtendedPacket{client.nextID(), "thisDoesn'tExist", "foobar"} - _, _, err := client.sendRequest(badPacket) + _, _, err := client.clientConn.sendPacket(badPacket) if err == nil { t.Fatal("expected error from bad packet") }