Add placeholder support for ListR interface.

The ListR interface will be implemented by remotes that can do a
recursive directory listing more efficiently than just recursing
through the directories.  These include the bucket based remotes.
This commit is contained in:
Nick Craig-Wood 2017-06-05 16:14:24 +01:00
parent 0edb025257
commit 53c3e5f0ab
7 changed files with 75 additions and 2 deletions

View file

@ -595,6 +595,12 @@ func (f *Fs) List(out fs.ListOpts, dir string) {
return return
} }
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
func (f *Fs) ListR(out fs.ListOpts, dir string) {
f.List(out, dir) // FIXME
}
// listBucketFn is called from listBucketsToFn to handle a bucket // listBucketFn is called from listBucketsToFn to handle a bucket
type listBucketFn func(*api.Bucket) error type listBucketFn func(*api.Bucket) error
@ -1365,6 +1371,7 @@ var (
_ fs.Fs = &Fs{} _ fs.Fs = &Fs{}
_ fs.Purger = &Fs{} _ fs.Purger = &Fs{}
_ fs.CleanUpper = &Fs{} _ fs.CleanUpper = &Fs{}
_ fs.ListRer = &Fs{}
_ fs.Object = &Object{} _ fs.Object = &Object{}
_ fs.MimeTyper = &Object{} _ fs.MimeTyper = &Object{}
) )

View file

@ -16,6 +16,9 @@ API v1, and at least the last path component will have the correct
casing. Changes to only the casing of paths won't be returned by casing. Changes to only the casing of paths won't be returned by
list_folder/continue. This field will be null if the file or folder is list_folder/continue. This field will be null if the file or folder is
not mounted. This field is optional. not mounted. This field is optional.
This only becomes a problem if dropbox implements the ListR interface
which it currently doesn't.
*/ */
import ( import (

View file

@ -295,6 +295,19 @@ type Features struct {
// Implement this if you have a way of emptying the trash or // Implement this if you have a way of emptying the trash or
// otherwise cleaning up old versions of files. // otherwise cleaning up old versions of files.
CleanUp func() error CleanUp func() error
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
//
// dir should be "" to start from the root, and should not
// have trailing slashes.
//
// This should return ErrDirNotFound (using out.SetError())
// if the directory isn't found.
//
// Don't implement this unless you have a more efficient way
// of listing recursively that doing a directory traversal.
ListR func(out ListOpts, dir string)
} }
// Fill fills in the function pointers in the Features struct from the // Fill fills in the function pointers in the Features struct from the
@ -328,6 +341,9 @@ func (ft *Features) Fill(f Fs) *Features {
if do, ok := f.(CleanUpper); ok { if do, ok := f.(CleanUpper); ok {
ft.CleanUp = do.CleanUp ft.CleanUp = do.CleanUp
} }
if do, ok := f.(ListRer); ok {
ft.ListR = do.ListR
}
return ft return ft
} }
@ -370,6 +386,9 @@ func (ft *Features) Mask(f Fs) *Features {
if mask.CleanUp == nil { if mask.CleanUp == nil {
ft.CleanUp = nil ft.CleanUp = nil
} }
if mask.ListR == nil {
ft.ListR = nil
}
return ft return ft
} }
@ -479,6 +498,22 @@ type CleanUpper interface {
CleanUp() error CleanUp() error
} }
// ListRer is an optional interfaces for Fs
type ListRer interface {
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
//
// dir should be "" to start from the root, and should not
// have trailing slashes.
//
// This should return ErrDirNotFound (using out.SetError())
// if the directory isn't found.
//
// Don't implement this unless you have a more efficient way
// of listing recursively that doing a directory traversal.
ListR(out ListOpts, dir string)
}
// ObjectsChan is a channel of Objects // ObjectsChan is a channel of Objects
type ObjectsChan chan Object type ObjectsChan chan Object

View file

@ -443,6 +443,12 @@ func (f *Fs) List(out fs.ListOpts, dir string) {
return return
} }
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
func (f *Fs) ListR(out fs.ListOpts, dir string) {
f.List(out, dir) // FIXME
}
// Put the object into the bucket // Put the object into the bucket
// //
// Copy the reader in to the new object which is returned // Copy the reader in to the new object which is returned
@ -736,6 +742,7 @@ func (o *Object) MimeType() string {
var ( var (
_ fs.Fs = &Fs{} _ fs.Fs = &Fs{}
_ fs.Copier = &Fs{} _ fs.Copier = &Fs{}
_ fs.ListRer = &Fs{}
_ fs.Object = &Object{} _ fs.Object = &Object{}
_ fs.MimeTyper = &Object{} _ fs.MimeTyper = &Object{}
) )

View file

@ -626,6 +626,12 @@ func (f *Fs) List(out fs.ListOpts, dir string) {
return return
} }
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
func (f *Fs) ListR(out fs.ListOpts, dir string) {
f.List(out, dir) // FIXME
}
// Put the Object into the bucket // Put the Object into the bucket
func (f *Fs) Put(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) { func (f *Fs) Put(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
// Temporary Object under construction // Temporary Object under construction
@ -998,6 +1004,7 @@ func (o *Object) MimeType() string {
var ( var (
_ fs.Fs = &Fs{} _ fs.Fs = &Fs{}
_ fs.Copier = &Fs{} _ fs.Copier = &Fs{}
_ fs.ListRer = &Fs{}
_ fs.Object = &Object{} _ fs.Object = &Object{}
_ fs.MimeTyper = &Object{} _ fs.MimeTyper = &Object{}
) )

View file

@ -397,6 +397,12 @@ func (f *Fs) List(out fs.ListOpts, dir string) {
return return
} }
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
func (f *Fs) ListR(out fs.ListOpts, dir string) {
f.List(out, dir) // FIXME
}
// Put the object into the container // Put the object into the container
// //
// Copy the reader in to the new object which is returned // Copy the reader in to the new object which is returned
@ -830,6 +836,7 @@ var (
_ fs.Fs = &Fs{} _ fs.Fs = &Fs{}
_ fs.Purger = &Fs{} _ fs.Purger = &Fs{}
_ fs.Copier = &Fs{} _ fs.Copier = &Fs{}
_ fs.ListRer = &Fs{}
_ fs.Object = &Object{} _ fs.Object = &Object{}
_ fs.MimeTyper = &Object{} _ fs.MimeTyper = &Object{}
) )

View file

@ -326,6 +326,12 @@ func (f *Fs) List(out fs.ListOpts, dir string) {
} }
} }
// ListR lists the objects and directories of the Fs starting
// from dir recursively into out.
func (f *Fs) ListR(out fs.ListOpts, dir string) {
f.List(out, dir) // FIXME
}
// NewObject finds the Object at remote. If it can't be found it // NewObject finds the Object at remote. If it can't be found it
// returns the error fs.ErrorObjectNotFound. // returns the error fs.ErrorObjectNotFound.
func (f *Fs) NewObject(remote string) (fs.Object, error) { func (f *Fs) NewObject(remote string) (fs.Object, error) {
@ -649,6 +655,7 @@ func (o *Object) MimeType() string {
var ( var (
_ fs.Fs = (*Fs)(nil) _ fs.Fs = (*Fs)(nil)
_ fs.Purger = (*Fs)(nil) _ fs.Purger = (*Fs)(nil)
_ fs.ListRer = (*Fs)(nil)
//_ fs.Copier = (*Fs)(nil) //_ fs.Copier = (*Fs)(nil)
_ fs.Object = (*Object)(nil) _ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{} _ fs.MimeTyper = &Object{}