diff --git a/server/server/commands.go b/server/server/commands.go index a6a2397..5433fe0 100644 --- a/server/server/commands.go +++ b/server/server/commands.go @@ -18,12 +18,7 @@ func GetFile(c Client, path string) (int, error) { return 0, ErrSlashNotAllowed } - stack, ok := c.Stack().(*StringStack) - if !ok { - return 0, ErrStackCast - } - - file, err := os.Open(MakePathFromStringStack(stack) + fileName) + file, err := os.Open(MakePathFromStringStack(c.Stack()) + fileName) if err != nil { log.Println(err.Error()) return 0, err @@ -68,12 +63,8 @@ func sanitizeFilePath(path string) (string, bool) { // ListFiles list the files from path and sends them to the connection func ListFiles(c Client) error { - stack, ok := c.Stack().(*StringStack) - if !ok { - return ErrStackCast - } - files, err := ioutil.ReadDir(MakePathFromStringStack(stack)) + files, err := ioutil.ReadDir(MakePathFromStringStack(c.Stack())) if err != nil { return err } @@ -110,17 +101,12 @@ func ChangeDirectoryCommand(c Client, directory string) error { return ErrSlashNotAllowed } - stack, ok := c.Stack().(*StringStack) - if !ok { - return ErrStackCast - } - if path == "." { err = nil } else if path == ".." { - err = ChangeDirectoryToPrevious(stack) + err = ChangeDirectoryToPrevious(c.Stack()) } else { - err = ChangeDirectory(stack, path) + err = ChangeDirectory(c.Stack(), path) } return err diff --git a/server/server/connection.go b/server/server/connection.go index c284485..b248138 100644 --- a/server/server/connection.go +++ b/server/server/connection.go @@ -18,7 +18,7 @@ type Client interface { Connection() net.Conn // Connection returns the connection stream. SetConnection(conn net.Conn) // SetConnection sets the connection for the client. Disconnect() // Disconnect closes the Client's connections and clears up resources. - Stack() Stack // Returns the underlying String Stack. + Stack() *StringStack // Returns the underlying String Stack. } // FTPClient represents a FTPClient connection, it holds a root cage and the underlying connection. @@ -28,7 +28,7 @@ type FTPClient struct { } // Stack returns the root cage stack. -func (c *FTPClient) Stack() Stack { +func (c *FTPClient) Stack() *StringStack { return c.rootCage }