Skip to content

Commit

Permalink
linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fclairamb committed Mar 2, 2024
1 parent 2b5066f commit ce56eec
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions asciiconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *asciiConverter) Read(p []byte) (n int, err error) {
} else {
data, _, err = c.reader.ReadLine()
if err != nil {
return
return -1, err
}
}

Expand All @@ -64,7 +64,7 @@ func (c *asciiConverter) Read(p []byte) (n int, err error) {
// client transfers it in ASCII mode
err = c.reader.UnreadByte()
if err != nil {
return
return -1, err
}

lastByte, err := c.reader.ReadByte()
Expand Down
2 changes: 1 addition & 1 deletion client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (c *clientHandler) writeLine(line string) {
c.logger.Debug("Sending answer", "line", line)
}

if _, err := c.writer.WriteString(fmt.Sprintf("%s\r\n", line)); err != nil {
if _, err := fmt.Fprintf(c.writer, "%s\r\n", line); err != nil {
c.logger.Warn(
"Answer couldn't be sent",
"line", line,
Expand Down
11 changes: 6 additions & 5 deletions client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func TestClientContextConcurrency(t *testing.T) {
for counter < 100 {
_, err := c.Getwd()
assert.NoError(t, err)

counter++
}

Expand Down Expand Up @@ -350,11 +351,11 @@ type testNetConn struct {
remoteAddr net.Addr
}

func (*testNetConn) Read(b []byte) (n int, err error) {
func (*testNetConn) Read(_ []byte) (n int, err error) {
return
}

func (*testNetConn) Write(b []byte) (n int, err error) {
func (*testNetConn) Write(_ []byte) (n int, err error) {
return
}

Expand All @@ -370,15 +371,15 @@ func (c *testNetConn) RemoteAddr() net.Addr {
return c.remoteAddr
}

func (*testNetConn) SetDeadline(t time.Time) error {
func (*testNetConn) SetDeadline(_ time.Time) error {
return nil
}

func (*testNetConn) SetReadDeadline(t time.Time) error {
func (*testNetConn) SetReadDeadline(_ time.Time) error {
return nil
}

func (*testNetConn) SetWriteDeadline(t time.Time) error {
func (*testNetConn) SetWriteDeadline(_ time.Time) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion control_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// Control defines the function to use as dialer Control to reuse the same port/address
func Control(network, address string, c syscall.RawConn) error {
func Control(_, _ string, c syscall.RawConn) error {
var errSetOpts error

err := c.Control(func(fd uintptr) {
Expand Down
7 changes: 4 additions & 3 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewTestServerWithDriver(t *testing.T, driver *TestServerDriver) *FtpServer
if err := os.MkdirAll(dir, 0750); err != nil {
panic(err)
}

driver.fs = afero.NewBasePathFs(afero.NewOsFs(), dir)
}

Expand Down Expand Up @@ -342,12 +343,12 @@ func (driver *TestServerDriver) GetTLSConfig() (*tls.Config, error) {
return nil, errNoTLS
}

func (driver *TestServerDriver) PreAuthUser(cc ClientContext, user string) error {
func (driver *TestServerDriver) PreAuthUser(cc ClientContext, _ string) error {
return cc.SetTLSRequirement(driver.TLSRequirement)
}

func (driver *TestServerDriver) VerifyConnection(cc ClientContext, user string,
tlsConn *tls.Conn) (ClientDriver, error) {
func (driver *TestServerDriver) VerifyConnection(_ ClientContext, _ string,
_ *tls.Conn) (ClientDriver, error) {
switch driver.TLSVerificationReply {
case tlsVerificationFailed:
return nil, errInvalidTLSCertificate
Expand Down
2 changes: 1 addition & 1 deletion handle_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *clientHandler) handlePASS(param string) error {

c.writeMessage(StatusNotLoggedIn, msg)
c.disconnect()
case err == nil:
default: // err == nil && c.driver != nil
if msg == "" {
msg = "Password ok, continue"
}
Expand Down
4 changes: 2 additions & 2 deletions handle_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *clientHandler) handleRMDIR(params string) {
}
}

func (c *clientHandler) handleCDUP(param string) error {
func (c *clientHandler) handleCDUP(_ string) error {
parent, _ := path.Split(c.Path())
if parent != "/" && strings.HasSuffix(parent, "/") {
parent = parent[0 : len(parent)-1]
Expand All @@ -156,7 +156,7 @@ func (c *clientHandler) handleCDUP(param string) error {
return nil
}

func (c *clientHandler) handlePWD(param string) error {
func (c *clientHandler) handlePWD(_ string) error {
c.writeMessage(StatusPathCreated, fmt.Sprintf(`"%s" is the current directory`, quoteDoubling(c.Path())))

return nil
Expand Down
3 changes: 3 additions & 0 deletions handle_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (c *clientHandler) doFileTransfer(tr net.Conn, file io.ReadWriter, write bo
"Stream copy finished",
"writtenBytes", written,
)

if written == 0 {
_, err = out.Write([]byte{})
}
Expand Down Expand Up @@ -293,6 +294,7 @@ func (c *clientHandler) handleCHOWN(params string) {
{
usergroup := strings.Split(spl[0], ":")
userName := usergroup[0]

if id, err := strconv.ParseInt(userName, 10, 32); err == nil {
userID = int(id)
} else {
Expand Down Expand Up @@ -432,6 +434,7 @@ func (c *clientHandler) handleSTATFile(param string) error {

return nil
}

files, errList = directory.Readdir(-1)
c.closeDirectory(directoryPath, directory)
}
Expand Down
10 changes: 5 additions & 5 deletions handle_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func (c *clientHandler) handlePROT(param string) error {
return nil
}

func (c *clientHandler) handlePBSZ(param string) error {
func (c *clientHandler) handlePBSZ(_ string) error {
c.writeMessage(StatusOK, "Whatever")

return nil
}

func (c *clientHandler) handleSYST(param string) error {
func (c *clientHandler) handleSYST(_ string) error {
if c.server.settings.DisableSYST {
c.writeMessage(StatusCommandNotImplemented, "SYST is disabled")

Expand Down Expand Up @@ -177,7 +177,7 @@ func (c *clientHandler) handleOPTS(param string) error {
return nil
}

func (c *clientHandler) handleNOOP(param string) error {
func (c *clientHandler) handleNOOP(_ string) error {
c.writeMessage(StatusOK, "OK")

return nil
Expand All @@ -190,7 +190,7 @@ func (c *clientHandler) handleCLNT(param string) error {
return nil
}

func (c *clientHandler) handleFEAT(param string) error {
func (c *clientHandler) handleFEAT(_ string) error {
c.writeLine(fmt.Sprintf("%d- These are my features", StatusSystemStatus))
defer c.writeMessage(StatusSystemStatus, "end")

Expand Down Expand Up @@ -272,7 +272,7 @@ func (c *clientHandler) handleTYPE(param string) error {
return nil
}

func (c *clientHandler) handleQUIT(param string) error {
func (c *clientHandler) handleQUIT(_ string) error {
c.transferWg.Wait()

var msg string
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (server *FtpServer) Listen() error {

return err
}

if server.settings.TLSRequired == ImplicitEncryption {
// implicit TLS
var tlsConfig *tls.Config
Expand All @@ -184,6 +185,7 @@ func (server *FtpServer) Listen() error {

return err
}

server.listener = tls.NewListener(server.listener, tlsConfig)
}
}
Expand Down
2 changes: 1 addition & 1 deletion transfer_pasv.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *clientHandler) findListenerWithinPortRange(portRange *PortRange) (*net.
return nil, ErrNoAvailableListeningPort
}

func (c *clientHandler) handlePASV(param string) error {
func (c *clientHandler) handlePASV(_ string) error {
command := c.GetLastCommand()
addr, _ := net.ResolveTCPAddr("tcp", ":0")
var tcpListener *net.TCPListener
Expand Down
5 changes: 3 additions & 2 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func ftpUpload(t *testing.T, ftp *goftp.Client, file io.ReadSeeker, filename str
if strings.HasSuffix(stats.Name(), filename) {
found = true
}

if !found {
t.Fatal("STAT: Couldn't find file !")
}
Expand Down Expand Up @@ -959,7 +960,7 @@ func TestPASVPublicIPResolver(t *testing.T) {
require.NoError(t, err, "Couldn't open raw connection")

s.settings.PublicHost = ""
s.settings.PublicIPResolver = func(cc ClientContext) (string, error) {
s.settings.PublicIPResolver = func(_ ClientContext) (string, error) {
return "127.0.0", nil
}
// we crash if the PublicIPResolver returns an invalid IP, this must be fixed outside the lib
Expand All @@ -968,7 +969,7 @@ func TestPASVPublicIPResolver(t *testing.T) {
require.Equal(t, StatusServiceNotAvailable, rc)
require.Contains(t, resp, "invalid passive IP")

s.settings.PublicIPResolver = func(cc ClientContext) (string, error) {
s.settings.PublicIPResolver = func(_ ClientContext) (string, error) {
return "", errConnectionNotAllowed
}

Expand Down

0 comments on commit ce56eec

Please sign in to comment.