Fix lint
All checks were successful
checks / check and test (pull_request) Successful in 36s

This commit is contained in:
2025-08-23 21:41:12 -07:00
parent 6fe7cebc70
commit 8f4de53d46

134
cmd.go
View File

@@ -24,58 +24,56 @@ type Command interface {
Execute(*Session, string)
}
var (
defaultCommands = map[string]Command{
"ADAT": commandAdat{},
"ALLO": commandAllo{},
"APPE": commandAppe{},
"AUTH": commandAuth{},
"CDUP": commandCdup{},
"CWD": commandCwd{},
"CCC": commandCcc{},
"CONF": commandConf{},
"CLNT": commandCLNT{},
"DELE": commandDele{},
"ENC": commandEnc{},
"EPRT": commandEprt{},
"EPSV": commandEpsv{},
"FEAT": commandFeat{},
"LIST": commandList{},
"LPRT": commandLprt{},
"NLST": commandNlst{},
"MDTM": commandMdtm{},
"MIC": commandMic{},
"MLSD": commandMLSD{},
"MKD": commandMkd{},
"MODE": commandMode{},
"NOOP": commandNoop{},
"OPTS": commandOpts{},
"PASS": commandPass{},
"PASV": commandPasv{},
"PBSZ": commandPbsz{},
"PORT": commandPort{},
"PROT": commandProt{},
"PWD": commandPwd{},
"QUIT": commandQuit{},
"RETR": commandRetr{},
"REST": commandRest{},
"RNFR": commandRnfr{},
"RNTO": commandRnto{},
"RMD": commandRmd{},
"SIZE": commandSize{},
"STAT": commandStat{},
"STOR": commandStor{},
"STRU": commandStru{},
"SYST": commandSyst{},
"TYPE": commandType{},
"USER": commandUser{},
"XCUP": commandCdup{},
"XCWD": commandCwd{},
"XMKD": commandMkd{},
"XPWD": commandPwd{},
"XRMD": commandXRmd{},
}
)
var defaultCommands = map[string]Command{
"ADAT": commandAdat{},
"ALLO": commandAllo{},
"APPE": commandAppe{},
"AUTH": commandAuth{},
"CDUP": commandCdup{},
"CWD": commandCwd{},
"CCC": commandCcc{},
"CONF": commandConf{},
"CLNT": commandCLNT{},
"DELE": commandDele{},
"ENC": commandEnc{},
"EPRT": commandEprt{},
"EPSV": commandEpsv{},
"FEAT": commandFeat{},
"LIST": commandList{},
"LPRT": commandLprt{},
"NLST": commandNlst{},
"MDTM": commandMdtm{},
"MIC": commandMic{},
"MLSD": commandMLSD{},
"MKD": commandMkd{},
"MODE": commandMode{},
"NOOP": commandNoop{},
"OPTS": commandOpts{},
"PASS": commandPass{},
"PASV": commandPasv{},
"PBSZ": commandPbsz{},
"PORT": commandPort{},
"PROT": commandProt{},
"PWD": commandPwd{},
"QUIT": commandQuit{},
"RETR": commandRetr{},
"REST": commandRest{},
"RNFR": commandRnfr{},
"RNTO": commandRnto{},
"RMD": commandRmd{},
"SIZE": commandSize{},
"STAT": commandStat{},
"STOR": commandStor{},
"STRU": commandStru{},
"SYST": commandSyst{},
"TYPE": commandType{},
"USER": commandUser{},
"XCUP": commandCdup{},
"XCWD": commandCwd{},
"XMKD": commandMkd{},
"XPWD": commandPwd{},
"XRMD": commandXRmd{},
}
// DefaultCommands returns the default commands
func DefaultCommands() map[string]Command {
@@ -131,7 +129,7 @@ func (cmd commandAppe) Execute(sess *Session, param string) {
sess.lastFilePos = -1
}()
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "APPE",
Param: param,
@@ -257,7 +255,7 @@ func (cmd commandCwd) RequireAuth() bool {
func (cmd commandCwd) Execute(sess *Session, param string) {
path := sess.buildPath(param)
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "CWD",
Param: param,
@@ -303,7 +301,7 @@ func (cmd commandDele) RequireAuth() bool {
func (cmd commandDele) Execute(sess *Session, param string) {
path := sess.buildPath(param)
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "DELE",
Param: param,
@@ -510,7 +508,7 @@ func convertFileInfo(sess *Session, f os.FileInfo, p string) (FileInfo, error) {
}
func list(sess *Session, cmd, p, param string) ([]FileInfo, error) {
var ctx = &Context{
ctx := &Context{
Sess: sess,
Cmd: cmd,
Param: param,
@@ -574,7 +572,7 @@ func parseListParam(param string) (path string) {
}
i = strings.LastIndex(param, " "+field) + len(field) + 1
}
path = strings.TrimLeft(param[i:], " ") //Get all the path even with space inside
path = strings.TrimLeft(param[i:], " ") // Get all the path even with space inside
}
return path
}
@@ -596,7 +594,7 @@ func (cmd commandNlst) RequireAuth() bool {
}
func (cmd commandNlst) Execute(sess *Session, param string) {
var ctx = &Context{
ctx := &Context{
Sess: sess,
Cmd: "NLST",
Param: param,
@@ -647,7 +645,7 @@ func (cmd commandNlst) Execute(sess *Session, param string) {
}
// commandMdtm responds to the MDTM FTP command. It allows the client to
// retreive the last modified time of a file.
// retrieve the last modified time of a file.
type commandMdtm struct{}
func (cmd commandMdtm) IsExtend() bool {
@@ -695,7 +693,7 @@ func (cmd commandMkd) RequireAuth() bool {
func (cmd commandMkd) Execute(sess *Session, param string) {
path := sess.buildPath(param)
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "MKD",
Param: param,
@@ -783,7 +781,7 @@ func (cmd commandPass) Execute(sess *Session, param string) {
if driverAuth, found := sess.server.Driver.(Auth); found {
auth = driverAuth
}
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "PASS",
Param: param,
@@ -946,14 +944,14 @@ func (cmd commandRetr) Execute(sess *Session, param string) {
defer func() {
sess.lastFilePos = -1
}()
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "RETR",
Param: param,
Data: make(map[string]interface{}),
}
sess.server.notifiers.BeforeDownloadFile(&ctx, path)
var readPos = sess.lastFilePos
readPos := sess.lastFilePos
if readPos < 0 {
readPos = 0
}
@@ -1106,7 +1104,7 @@ func (cmd commandXRmd) Execute(sess *Session, param string) {
func executeRmd(cmd string, sess *Session, param string) {
p := sess.buildPath(param)
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: cmd,
Param: param,
@@ -1117,7 +1115,7 @@ func executeRmd(cmd string, sess *Session, param string) {
return
}
var needChangeCurDir = strings.HasPrefix(param, sess.curDir)
needChangeCurDir := strings.HasPrefix(param, sess.curDir)
sess.server.notifiers.BeforeDeleteDir(&ctx, p)
err := sess.server.Driver.DeleteDir(&ctx, p)
@@ -1247,7 +1245,7 @@ func (cmd commandMLSD) RequireAuth() bool {
func toMLSDFormat(files []FileInfo) []byte {
var buf bytes.Buffer
for _, file := range files {
var fileType = "file"
fileType := "file"
if file.IsDir() {
fileType = "dir"
}
@@ -1409,7 +1407,7 @@ func (cmd commandStat) Execute(sess *Session, param string) {
return
}
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "STAT",
Param: param,
@@ -1479,7 +1477,7 @@ func (cmd commandStor) Execute(sess *Session, param string) {
sess.lastFilePos = -1
}()
var ctx = Context{
ctx := Context{
Sess: sess,
Cmd: "STOR",
Param: param,