Refactoring Client to have StringStack instead of stack
This commit is contained in:
parent
13a2d7db65
commit
6d96530227
2 changed files with 6 additions and 20 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue