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
|
return 0, ErrSlashNotAllowed
|
||||||
}
|
}
|
||||||
|
|
||||||
stack, ok := c.Stack().(*StringStack)
|
file, err := os.Open(MakePathFromStringStack(c.Stack()) + fileName)
|
||||||
if !ok {
|
|
||||||
return 0, ErrStackCast
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := os.Open(MakePathFromStringStack(stack) + fileName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return 0, err
|
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
|
// ListFiles list the files from path and sends them to the connection
|
||||||
func ListFiles(c Client) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -110,17 +101,12 @@ func ChangeDirectoryCommand(c Client, directory string) error {
|
||||||
return ErrSlashNotAllowed
|
return ErrSlashNotAllowed
|
||||||
}
|
}
|
||||||
|
|
||||||
stack, ok := c.Stack().(*StringStack)
|
|
||||||
if !ok {
|
|
||||||
return ErrStackCast
|
|
||||||
}
|
|
||||||
|
|
||||||
if path == "." {
|
if path == "." {
|
||||||
err = nil
|
err = nil
|
||||||
} else if path == ".." {
|
} else if path == ".." {
|
||||||
err = ChangeDirectoryToPrevious(stack)
|
err = ChangeDirectoryToPrevious(c.Stack())
|
||||||
} else {
|
} else {
|
||||||
err = ChangeDirectory(stack, path)
|
err = ChangeDirectory(c.Stack(), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -18,7 +18,7 @@ type Client interface {
|
||||||
Connection() net.Conn // Connection returns the connection stream.
|
Connection() net.Conn // Connection returns the connection stream.
|
||||||
SetConnection(conn net.Conn) // SetConnection sets the connection for the client.
|
SetConnection(conn net.Conn) // SetConnection sets the connection for the client.
|
||||||
Disconnect() // Disconnect closes the Client's connections and clears up resources.
|
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.
|
// 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.
|
// Stack returns the root cage stack.
|
||||||
func (c *FTPClient) Stack() Stack {
|
func (c *FTPClient) Stack() *StringStack {
|
||||||
return c.rootCage
|
return c.rootCage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue