Skip to content

Commit 16857ee

Browse files
committed
Debug directory listings
1 parent 08390f8 commit 16857ee

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

debug.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,19 @@ func newDebugWrapper(conn io.ReadWriteCloser, w io.Writer) io.ReadWriteCloser {
1919
func (w *debugWrapper) Close() error {
2020
return w.conn.Close()
2121
}
22+
23+
type debugWrapperR struct {
24+
rd io.ReadCloser
25+
io.Reader
26+
}
27+
28+
func newDebugWrapperR(rd io.ReadCloser, w io.Writer) io.ReadCloser {
29+
return &debugWrapperR{
30+
Reader: io.TeeReader(rd, w),
31+
rd: rd,
32+
}
33+
}
34+
35+
func (w *debugWrapperR) Close() error {
36+
return w.rd.Close()
37+
}

ftp.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ func (o *dialOptions) wrapConn(netConn net.Conn) io.ReadWriteCloser {
263263
return newDebugWrapper(netConn, o.debugOutput)
264264
}
265265

266+
func (o *dialOptions) wrapStream(rd io.ReadCloser) io.ReadCloser {
267+
if o.debugOutput == nil {
268+
return rd
269+
}
270+
271+
return newDebugWrapperR(rd, o.debugOutput)
272+
}
273+
266274
// Connect is an alias to Dial, for backward compatibility
267275
func Connect(addr string) (*ServerConn, error) {
268276
return Dial(addr)
@@ -573,7 +581,7 @@ func (c *ServerConn) NameList(path string) (entries []string, err error) {
573581
}
574582
}()
575583

576-
scanner := bufio.NewScanner(r)
584+
scanner := bufio.NewScanner(c.options.wrapStream(r))
577585
for scanner.Scan() {
578586
entries = append(entries, scanner.Text())
579587
}
@@ -612,7 +620,7 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
612620
}
613621
}()
614622

615-
scanner := bufio.NewScanner(r)
623+
scanner := bufio.NewScanner(c.options.wrapStream(r))
616624
now := time.Now()
617625
for scanner.Scan() {
618626
entry, errParse := parser(scanner.Text(), now, c.options.location)

0 commit comments

Comments
 (0)