Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"net"
"os"
"sync"
"time"
)
Expand Down Expand Up @@ -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 {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
Expand Down
6 changes: 6 additions & 0 deletions file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the skipSelfParent flag? (I think its purpose is to exclude "." and ".." when listing.) Perhaps instead of passing that flag into the parser, we could exclude "." and ".." here using the return value?

}
return parseLIST(entry, c.config.ServerLocation, skipSelfParent)
}
}
Expand Down Expand Up @@ -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
Expand Down