From 67d08ff08ab032535dfe3487b552bcab58ec748e Mon Sep 17 00:00:00 2001 From: Samuel Simpson Date: Mon, 11 Feb 2019 09:25:47 -0500 Subject: [PATCH] add custom list parser config option --- client.go | 7 +++++++ file_system.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/client.go b/client.go index d08d144..4512523 100644 --- a/client.go +++ b/client.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "net" + "os" "sync" "time" ) @@ -149,6 +150,12 @@ type Config struct { // hung connections. DisableEPSV bool + // Provide a custom parser for the outcome of the LIST command + // If this is not set, a default LIST parser is used that will handle most outcomes + ListParser interface { + ParseLIST(entry string) (os.FileInfo, error) + } + // For testing convenience. stubResponses map[string]stubResponse } diff --git a/file_system.go b/file_system.go index d80bf40..7695c22 100644 --- a/file_system.go +++ b/file_system.go @@ -139,6 +139,9 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { return nil, err } parser = func(entry string, skipSelfParent bool) (os.FileInfo, error) { + if c.config.ListParser != nil { + return c.config.ListParser.ParseLIST(entry) + } return parseLIST(entry, c.config.ServerLocation, skipSelfParent) } } @@ -179,6 +182,9 @@ func (c *Client) Stat(path string) (os.FileInfo, error) { return nil, ftpError{err: fmt.Errorf("unexpected LIST response: %v", lines)} } + if c.config.ListParser != nil { + return c.config.ListParser.ParseLIST(lines[0]) + } return parseLIST(lines[0], c.config.ServerLocation, false) } return nil, err