diff --git a/http/http.go b/http/http.go index 7a67dcdad..87f8f4f7c 100644 --- a/http/http.go +++ b/http/http.go @@ -16,15 +16,15 @@ import ( "path" "strconv" "strings" - "sync" "time" - "golang.org/x/net/html" - "github.com/ncw/rclone/fs" "github.com/pkg/errors" + "golang.org/x/net/html" ) +var errorReadOnly = errors.New("http remotes are read only") + func init() { fsi := &fs.RegInfo{ Name: "http", @@ -32,10 +32,10 @@ func init() { NewFs: NewFs, Options: []fs.Option{{ Name: "endpoint", - Help: "http host to connect to", + Help: "URL of http host to connect to", Optional: false, Examples: []fs.OptionExample{{ - Value: "example.com", + Value: "https://example.com", Help: "Connect to example.com", }}, }}, @@ -278,24 +278,34 @@ func (f *Fs) readDir(p string) ([]*entry, error) { return entries, nil } -func (f *Fs) list(out fs.ListOpts, dir string, level int, wg *sync.WaitGroup, tokens chan struct{}) { - defer wg.Done() - // take a token - <-tokens - // return it when done - defer func() { - tokens <- struct{}{} - }() +// List the objects and directories in dir into entries. The +// entries can be returned in any order but should be for a +// complete directory. +// +// dir should be "" to list the root, and should not have +// trailing slashes. +// +// This should return ErrDirNotFound if the directory isn't +// found. +func (f *Fs) List(dir string) (entries fs.DirEntries, err error) { + endpoint := path.Join(f.root, dir) + if !strings.HasSuffix(dir, "/") { + endpoint += "/" + } + ok, err := f.dirExists(endpoint) + if err != nil { + return nil, errors.Wrap(err, "List failed") + } + if !ok { + return nil, fs.ErrorDirNotFound + } httpDir := path.Join(f.root, dir) if !strings.HasSuffix(dir, "/") { httpDir += "/" } infos, err := f.readDir(httpDir) if err != nil { - err = errors.Wrapf(err, "error listing %q", dir) - fs.Errorf(f, "Listing failed: %v", err) - out.SetError(err) - return + return nil, errors.Wrapf(err, "error listing %q", dir) } for _, info := range infos { remote := "" @@ -305,19 +315,13 @@ func (f *Fs) list(out fs.ListOpts, dir string, level int, wg *sync.WaitGroup, to remote = info.Name() } if info.IsDir() { - if out.IncludeDirectory(remote) { - dir := &fs.Dir{ - Name: remote, - When: info.ModTime(), - Bytes: 0, - Count: 0, - } - out.AddDir(dir) - if level < out.Level() { - wg.Add(1) - go f.list(out, remote, level+1, wg, tokens) - } + dir := &fs.Dir{ + Name: remote, + When: info.ModTime(), + Bytes: 0, + Count: 0, } + entries = append(entries, dir) } else { file := &Object{ fs: f, @@ -327,41 +331,19 @@ func (f *Fs) list(out fs.ListOpts, dir string, level int, wg *sync.WaitGroup, to if err = file.stat(); err != nil { continue } - out.Add(file) + entries = append(entries, file) } } + return entries, nil } -// List the files and directories starting at