Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

serve s3: fix listing oddities

Nick Craig-Wood486a10bec587
diff --git a/cmd/serve/s3/backend.go b/cmd/serve/s3/backend.go
index 397760102..4e88e418f 100644
--- a/cmd/serve/s3/backend.go
+++ b/cmd/serve/s3/backend.go
@@ -77,13 +77,9 @@ func (b *s3Backend) ListBucket(bucket string, prefix *gofakes3.Prefix, page gofa
}
response := gofakes3.NewObjectList()
- if b.vfs.Fs().Features().BucketBased || prefix.HasDelimiter && prefix.Delimiter != "/" {
- err = b.getObjectsListArbitrary(bucket, prefix, response)
- } else {
- path, remaining := prefixParser(prefix)
- err = b.entryListR(bucket, path, remaining, prefix.HasDelimiter, response)
- }
+ path, remaining := prefixParser(prefix)
+ err = b.entryListR(bucket, path, remaining, prefix.HasDelimiter, response)
if err == gofakes3.ErrNoSuchKey {
// AWS just returns an empty list
response = gofakes3.NewObjectList()
@@ -366,9 +362,7 @@ func (b *s3Backend) deleteObject(bucketName, objectName string) error {
}
// FIXME: unsafe operation
- if b.vfs.Fs().Features().CanHaveEmptyDirectories {
- rmdirRecursive(fp, b.vfs)
- }
+ rmdirRecursive(fp, b.vfs)
return nil
}
diff --git a/cmd/serve/s3/list.go b/cmd/serve/s3/list.go
index 93f0f87e3..d23736152 100644
--- a/cmd/serve/s3/list.go
+++ b/cmd/serve/s3/list.go
@@ -1,16 +1,13 @@
package s3
import (
- "context"
"path"
"strings"
"github.com/Mikubill/gofakes3"
- "github.com/rclone/rclone/fs"
- "github.com/rclone/rclone/fs/walk"
)
-func (b *s3Backend) entryListR(bucket, fdPath, name string, acceptComPrefix bool, response *gofakes3.ObjectList) error {
+func (b *s3Backend) entryListR(bucket, fdPath, name string, addPrefix bool, response *gofakes3.ObjectList) error {
fp := path.Join(bucket, fdPath)
dirEntries, err := getDirEntries(fp, b.vfs)
@@ -29,7 +26,7 @@ func (b *s3Backend) entryListR(bucket, fdPath, name string, acceptComPrefix bool
}
if entry.IsDir() {
- if acceptComPrefix {
+ if addPrefix {
response.AddPrefix(gofakes3.URLEncode(objectPath))
continue
}
@@ -50,36 +47,3 @@ func (b *s3Backend) entryListR(bucket, fdPath, name string, acceptComPrefix bool
}
return nil
}
-
-// getObjectsList lists the objects in the given bucket.
-func (b *s3Backend) getObjectsListArbitrary(bucket string, prefix *gofakes3.Prefix, response *gofakes3.ObjectList) error {
- // ignore error - vfs may have uncommitted updates, such as new dir etc.
- _ = walk.ListR(context.Background(), b.vfs.Fs(), bucket, false, -1, walk.ListObjects, func(entries fs.DirEntries) error {
- for _, entry := range entries {
- entry := entry.(fs.Object)
- objName := entry.Remote()
- object := strings.TrimPrefix(objName, bucket)[1:]
-
- var matchResult gofakes3.PrefixMatch
- if prefix.Match(object, &matchResult) {
- if matchResult.CommonPrefix {
- response.AddPrefix(gofakes3.URLEncode(object))
- continue
- }
-
- item := &gofakes3.Content{
- Key: gofakes3.URLEncode(object),
- LastModified: gofakes3.NewContentTime(entry.ModTime(context.Background())),
- ETag: getFileHash(entry),
- Size: entry.Size(),
- StorageClass: gofakes3.StorageStandard,
- }
- response.Add(item)
- }
- }
-
- return nil
- })
-
- return nil
-}