github.com/artpar/rclone@v1.67.3/cmd/serve/s3/list.go (about)

     1  package s3
     2  
     3  import (
     4  	"path"
     5  	"strings"
     6  
     7  	"github.com/rclone/gofakes3"
     8  )
     9  
    10  func (b *s3Backend) entryListR(bucket, fdPath, name string, addPrefix bool, response *gofakes3.ObjectList) error {
    11  	fp := path.Join(bucket, fdPath)
    12  
    13  	dirEntries, err := getDirEntries(fp, b.vfs)
    14  	if err != nil {
    15  		return err
    16  	}
    17  
    18  	for _, entry := range dirEntries {
    19  		object := entry.Name()
    20  
    21  		// workround for control-chars detect
    22  		objectPath := path.Join(fdPath, object)
    23  
    24  		if !strings.HasPrefix(object, name) {
    25  			continue
    26  		}
    27  
    28  		if entry.IsDir() {
    29  			if addPrefix {
    30  				response.AddPrefix(gofakes3.URLEncode(objectPath))
    31  				continue
    32  			}
    33  			err := b.entryListR(bucket, path.Join(fdPath, object), "", false, response)
    34  			if err != nil {
    35  				return err
    36  			}
    37  		} else {
    38  			item := &gofakes3.Content{
    39  				Key:          gofakes3.URLEncode(objectPath),
    40  				LastModified: gofakes3.NewContentTime(entry.ModTime()),
    41  				ETag:         getFileHash(entry),
    42  				Size:         entry.Size(),
    43  				StorageClass: gofakes3.StorageStandard,
    44  			}
    45  			response.Add(item)
    46  		}
    47  	}
    48  	return nil
    49  }