Return all errors from Stor functions
To not hide some errors
This commit is contained in:
parent
02685330ee
commit
fed5bc26b7
24
ftp.go
24
ftp.go
@ -15,6 +15,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
// EntryType describes the different types of an Entry.
|
||||
@ -804,6 +806,8 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
errs := &multierror.Error{}
|
||||
|
||||
// if the upload fails we still need to try to read the server
|
||||
// response otherwise if the failure is not due to a connection problem,
|
||||
// for example the server denied the upload for quota limits, we miss
|
||||
@ -822,23 +826,21 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error {
|
||||
// an empty file without this.
|
||||
if n == 0 && err == nil {
|
||||
if do, ok := conn.(interface{ Handshake() error }); ok {
|
||||
err = do.Handshake()
|
||||
if err := do.Handshake(); err != nil {
|
||||
multierror.Append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use io.Copy or Handshake error in preference to this one
|
||||
closeErr := conn.Close()
|
||||
if err == nil {
|
||||
err = closeErr
|
||||
if err := conn.Close(); err != nil {
|
||||
multierror.Append(errs, err)
|
||||
}
|
||||
|
||||
// Read the response and use this error in preference to
|
||||
// previous errors
|
||||
respErr := c.checkDataShut()
|
||||
if respErr != nil {
|
||||
err = respErr
|
||||
if err := c.checkDataShut(); err != nil {
|
||||
multierror.Append(errs, err)
|
||||
}
|
||||
return err
|
||||
|
||||
return errs.ErrorOrNil()
|
||||
}
|
||||
|
||||
// Append issues a APPE FTP command to store a file to the remote FTP server.
|
||||
|
14
go.mod
14
go.mod
@ -1,5 +1,15 @@
|
||||
module github.com/jlaffaye/ftp
|
||||
|
||||
go 1.14
|
||||
go 1.17
|
||||
|
||||
require github.com/stretchr/testify v1.6.1
|
||||
require (
|
||||
github.com/hashicorp/go-multierror v1.1.1
|
||||
github.com/stretchr/testify v1.6.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
5
go.sum
5
go.sum
@ -1,8 +1,11 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
|
Loading…
Reference in New Issue
Block a user