Some code improvement #107

Closed
lunny wants to merge 1 commits from lunny/code_improve into master
3 changed files with 22 additions and 8 deletions

24
cmd.go
View File

@ -298,12 +298,22 @@ func (cmd commandEprt) Execute(conn *Conn, param string) {
delim := string(param[0:1])
parts := strings.Split(param, delim)
addressFamily, err := strconv.Atoi(parts[1])
host := parts[2]
port, err := strconv.Atoi(parts[3])
if err != nil {
conn.writeMessage(522, "Network protocol not supported, use (1,2)")
return
}
if addressFamily != 1 && addressFamily != 2 {
conn.writeMessage(522, "Network protocol not supported, use (1,2)")
return
}
host := parts[2]
port, err := strconv.Atoi(parts[3])
if err != nil {
conn.writeMessage(522, "Network protocol not supported, use (1,2)")
return
}
socket, err := newActiveSocket(host, port, conn.logger, conn.sessionID)
if err != nil {
conn.writeMessage(425, "Data connection failed")
@ -336,13 +346,13 @@ func (cmd commandLprt) Execute(conn *Conn, param string) {
parts := strings.Split(param, ",")
addressFamily, err := strconv.Atoi(parts[0])
if addressFamily != 4 {
if err != nil || addressFamily != 4 {
conn.writeMessage(522, "Network protocol not supported, use 4")
return
}
addressLength, err := strconv.Atoi(parts[1])
if addressLength != 4 {
if err != nil || addressLength != 4 {
conn.writeMessage(522, "Network IP length not supported, use 4")
return
}
@ -405,7 +415,7 @@ func (cmd commandEpsv) Execute(conn *Conn, param string) {
conn.writeMessage(229, msg)
}
// commandList responds to the LIST FTP command. It allows the client to retreive
// commandList responds to the LIST FTP command. It allows the client to retrieve
// a detailed listing of the contents of a directory.
type commandList struct{}
@ -470,7 +480,7 @@ func parseListParam(param string) (path string) {
}
// commandNlst responds to the NLST FTP command. It allows the client to
// retreive a list of filenames in the current directory.
// retrieve a list of filenames in the current directory.
type commandNlst struct{}
func (cmd commandNlst) IsExtend() bool {
@ -511,7 +521,7 @@ func (cmd commandNlst) Execute(conn *Conn, 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 {

View File

@ -52,7 +52,7 @@ type Driver interface {
GetFile(string, int64) (int64, io.ReadCloser, error)
// params - destination path, an io.Reader containing the file data
// returns - the number of bytes writen and the first error encountered while writing, if any.
// returns - the number of bytes written and the first error encountered while writing, if any.
PutFile(string, io.Reader, bool) (int64, error)
}

View File

@ -155,15 +155,19 @@ func TestNotification(t *testing.T) {
assert.NoError(t, err)
err = f.MakeDir("/src")
assert.NoError(t, err)
assetMockNotifier(t, mock, []string{"BeforeCreateDir", "AfterDirCreated"})
err = f.Delete("/test.go")
assert.NoError(t, err)
assetMockNotifier(t, mock, []string{"BeforeDeleteFile", "AfterFileDeleted"})
err = f.ChangeDir("/src")
assert.NoError(t, err)
assetMockNotifier(t, mock, []string{"BeforeChangeCurDir", "AfterCurDirChanged"})
err = f.RemoveDir("/src")
assert.NoError(t, err)
assetMockNotifier(t, mock, []string{"BeforeDeleteDir", "AfterDirDeleted"})
err = f.Quit()