Debug directory listings

This commit is contained in:
Ivan Andreev 2021-08-22 02:48:50 +03:00
parent 5d41901190
commit ae8a71d543
2 changed files with 26 additions and 2 deletions

View File

@ -19,3 +19,19 @@ func newDebugWrapper(conn io.ReadWriteCloser, w io.Writer) io.ReadWriteCloser {
func (w *debugWrapper) Close() error {
return w.conn.Close()
}
type streamDebugWrapper struct {
io.Reader
closer io.ReadCloser
}
func newStreamDebugWrapper(rd io.ReadCloser, w io.Writer) io.ReadCloser {
return &streamDebugWrapper{
Reader: io.TeeReader(rd, w),
closer: rd,
}
}
func (w *streamDebugWrapper) Close() error {
return w.closer.Close()
}

12
ftp.go
View File

@ -251,6 +251,14 @@ func (o *dialOptions) wrapConn(netConn net.Conn) io.ReadWriteCloser {
return newDebugWrapper(netConn, o.debugOutput)
}
func (o *dialOptions) wrapStream(rd io.ReadCloser) io.ReadCloser {
if o.debugOutput == nil {
return rd
}
return newStreamDebugWrapper(rd, o.debugOutput)
}
// Connect is an alias to Dial, for backward compatibility
func Connect(addr string) (*ServerConn, error) {
return Dial(addr)
@ -561,7 +569,7 @@ func (c *ServerConn) NameList(path string) (entries []string, err error) {
}
}()
scanner := bufio.NewScanner(r)
scanner := bufio.NewScanner(c.options.wrapStream(r))
for scanner.Scan() {
entries = append(entries, scanner.Text())
}
@ -600,7 +608,7 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
}
}()
scanner := bufio.NewScanner(r)
scanner := bufio.NewScanner(c.options.wrapStream(r))
now := time.Now()
for scanner.Scan() {
entry, errParse := parser(scanner.Text(), now, c.options.location)