-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add ListParser as a config option #38
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add tests for the new functionality? |
||
ParseLIST(entry string) (os.FileInfo, error) | ||
} | ||
|
||
// For testing convenience. | ||
stubResponses map[string]stubResponse | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the |
||
} | ||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be a function instead of an interface?