@@ -401,12 +401,20 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
401401// This should return ErrDirNotFound if the directory isn't
402402// found.
403403func (f * Fs ) List (ctx context.Context , dir string ) (entries fs.DirEntries , err error ) {
404- if f .doiProvider .CanHaveSubDirs () {
405- fileEntries , err := f .doiProvider .ListEntries (ctx )
406- if err != nil {
407- return nil , fmt .Errorf ("error listing %q: %w" , dir , err )
408- }
404+ if ! f .doiProvider .CanHaveSubDirs () && dir != "" {
405+ return nil , fs .ErrorDirNotFound
406+ }
407+
408+ fileEntries , err := f .doiProvider .ListEntries (ctx )
409+ if err != nil {
410+ return nil , fmt .Errorf ("error listing %q: %w" , dir , err )
411+ }
409412
413+ if ! f .doiProvider .CanHaveSubDirs () {
414+ for _ , entry := range fileEntries {
415+ entries = append (entries , entry )
416+ }
417+ } else {
410418 fullDir := path .Join (f .root , dir )
411419 if fullDir != "" {
412420 fullDir += "/"
@@ -435,25 +443,9 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
435443 entry := fs .NewDir (dirPath , time.Time {})
436444 entries = append (entries , entry )
437445 }
438- return entries , nil
439- }
440-
441- if ! f .doiProvider .CanHaveSubDirs () {
442- if dir != "" {
443- return nil , fs .ErrorDirNotFound
444- }
445-
446- fileEntries , err := f .doiProvider .ListEntries (ctx )
447- if err != nil {
448- return nil , fmt .Errorf ("error listing %q: %w" , dir , err )
449- }
450- for _ , entry := range fileEntries {
451- entries = append (entries , entry )
452- }
453- return entries , nil
454446 }
455447
456- return nil , fmt . Errorf ( "provider type '%s' not supported" , f . provider )
448+ return entries , nil
457449}
458450
459451// Put in to the remote path with the modTime given of the given size
0 commit comments