Commit a467b74b authored by Bruce Flynn's avatar Bruce Flynn
Browse files

Fix IO slowness with interfaces added for testing

It appears use of the sftpFile struct as a io.WriteCloser was the issue
causing IO throupught to be half of previous versions. I cannot explain
exactly why this is the case, but I can speculate that it has something
to do with proxying the write through Write(buf []byte) which makes a
copy of the buf slice.
parent b36c091d
......@@ -42,18 +42,6 @@ type sftpClient interface {
Remove(string) error
}
type sftpFile struct {
Rem *sftp.File
}
func (f sftpFile) Close() error {
return f.Rem.Close()
}
func (f sftpFile) Write(buf []byte) (int, error) {
return f.Rem.Write(buf)
}
type mySFTPClient struct {
SFTP *sftp.Client
}
......@@ -63,11 +51,12 @@ func (c *mySFTPClient) Close() error {
}
func (c *mySFTPClient) Create(path string) (io.WriteCloser, error) {
var f io.WriteCloser
f, err := c.SFTP.Create(path)
if err != nil {
return sftpFile{}, err
return f, err
}
return sftpFile{f}, nil
return f, nil
}
func (c *mySFTPClient) Poke() bool {
......@@ -89,7 +78,7 @@ func (c *mySFTPClient) Remove(path string) error {
type sftpAPI struct {
URL *url_.URL
Client *sftp.Client
Client sftpClient
Cfg ssh.ClientConfig
Req io.Reader
Resp io.Writer
......@@ -285,7 +274,7 @@ func (s sftpAPI) doDelete(path string) error {
// make sure the client is connected by poking it
func (s *sftpAPI) ensureConnected() error {
if _, err := s.Client.Getwd(); err != nil {
if !s.Client.Poke() {
debug("not connected, connecting")
return s.connect()
}
......@@ -371,7 +360,7 @@ func (s *sftpAPI) connect() error {
if err != nil {
return err
}
s.Client = c
s.Client = &mySFTPClient{c}
return nil
}
......
package main
/*
import (
"bytes"
"encoding/binary"
......@@ -189,4 +188,3 @@ func TestAPIdoListdir(t *testing.T) {
assert.Greater(t, time.Now().Unix()+10, matches[1].MTime)
}
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment