mirror of
https://github.com/rclone/rclone.git
synced 2025-01-25 15:49:33 +01:00
ftp: add FTP List timeout, fixes #3086
The timeout is controlled by the --timeout flag
This commit is contained in:
parent
b88e50cc36
commit
c809334b3d
@ -345,11 +345,36 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "list")
|
return nil, errors.Wrap(err, "list")
|
||||||
}
|
}
|
||||||
files, err := c.List(path.Join(f.root, dir))
|
|
||||||
f.putFtpConnection(&c, err)
|
var listErr error
|
||||||
if err != nil {
|
var files []*ftp.Entry
|
||||||
return nil, translateErrorDir(err)
|
|
||||||
|
resultchan := make(chan []*ftp.Entry, 1)
|
||||||
|
errchan := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
result, err := c.List(path.Join(f.root, dir))
|
||||||
|
f.putFtpConnection(&c, err)
|
||||||
|
if err != nil {
|
||||||
|
errchan <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resultchan <- result
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Wait for List for up to Timeout seconds
|
||||||
|
timer := time.NewTimer(fs.Config.Timeout)
|
||||||
|
select {
|
||||||
|
case listErr = <-errchan:
|
||||||
|
timer.Stop()
|
||||||
|
return nil, translateErrorDir(listErr)
|
||||||
|
case files = <-resultchan:
|
||||||
|
timer.Stop()
|
||||||
|
case <-timer.C:
|
||||||
|
// if timer fired assume no error but connection dead
|
||||||
|
fs.Errorf(f, "Timeout when waiting for List")
|
||||||
|
return nil, errors.New("Timeout when waiting for List")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annoyingly FTP returns success for a directory which
|
// Annoyingly FTP returns success for a directory which
|
||||||
// doesn't exist, so check it really doesn't exist if no
|
// doesn't exist, so check it really doesn't exist if no
|
||||||
// entries found.
|
// entries found.
|
||||||
|
Loading…
Reference in New Issue
Block a user