Fix issues reported by shadow

This commit is contained in:
Julien Laffaye 2021-03-06 19:43:28 -05:00
parent 05cd33e2ad
commit 64cacdb711
2 changed files with 14 additions and 14 deletions

View File

@ -73,9 +73,9 @@ func testConn(t *testing.T, disableEPSV bool) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
buf, err := ioutil.ReadAll(r) buf, errRead := ioutil.ReadAll(r)
if err != nil { if err != nil {
t.Error(err) t.Error(errRead)
} }
if string(buf) != testData { if string(buf) != testData {
t.Errorf("'%s'", buf) t.Errorf("'%s'", buf)
@ -90,7 +90,7 @@ func testConn(t *testing.T, disableEPSV bool) {
t.Error(err) t.Error(err)
} else { } else {
r.SetDeadline(time.Now()) r.SetDeadline(time.Now())
_, err := ioutil.ReadAll(r) _, err = ioutil.ReadAll(r)
if err == nil { if err == nil {
t.Error("deadline should have caused error") t.Error("deadline should have caused error")
} else if !strings.HasSuffix(err.Error(), "i/o timeout") { } else if !strings.HasSuffix(err.Error(), "i/o timeout") {
@ -104,9 +104,9 @@ func testConn(t *testing.T, disableEPSV bool) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
buf, err := ioutil.ReadAll(r) buf, errRead := ioutil.ReadAll(r)
if err != nil { if errRead != nil {
t.Error(err) t.Error(errRead)
} }
expected := testData[5:] expected := testData[5:]
if string(buf) != expected { if string(buf) != expected {
@ -126,9 +126,9 @@ func testConn(t *testing.T, disableEPSV bool) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
buf, err := ioutil.ReadAll(r) buf, errRead := ioutil.ReadAll(r)
if err != nil { if err != nil {
t.Error(err) t.Error(errRead)
} }
if string(buf) != testData+testData { if string(buf) != testData+testData {
t.Errorf("'%s'", buf) t.Errorf("'%s'", buf)
@ -193,7 +193,7 @@ func testConn(t *testing.T, disableEPSV bool) {
} }
} }
if err := c.Quit(); err != nil { if err = c.Quit(); err != nil {
t.Fatal(err) t.Fatal(err)
} }

10
ftp.go
View File

@ -309,10 +309,10 @@ func (c *ServerConn) Login(user, password string) error {
// If using implicit TLS, make data connections also use TLS // If using implicit TLS, make data connections also use TLS
if c.options.tlsConfig != nil { if c.options.tlsConfig != nil {
if _, _, err := c.cmd(StatusCommandOK, "PBSZ 0"); err != nil { if _, _, err = c.cmd(StatusCommandOK, "PBSZ 0"); err != nil {
return err return err
} }
if _, _, err := c.cmd(StatusCommandOK, "PROT P"); err != nil { if _, _, err = c.cmd(StatusCommandOK, "PROT P"); err != nil {
return err return err
} }
} }
@ -516,7 +516,7 @@ func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...inter
} }
if offset != 0 { if offset != 0 {
_, _, err := c.cmd(StatusRequestFilePending, "REST %d", offset) _, _, err = c.cmd(StatusRequestFilePending, "REST %d", offset)
if err != nil { if err != nil {
_ = conn.Close() _ = conn.Close()
return nil, err return nil, err
@ -603,8 +603,8 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
now := time.Now() now := time.Now()
for scanner.Scan() { for scanner.Scan() {
entry, err := parser(scanner.Text(), now, c.options.location) entry, errParse := parser(scanner.Text(), now, c.options.location)
if err == nil { if errParse == nil {
entries = append(entries, entry) entries = append(entries, entry)
} }
} }