Skip to content

Commit 77fb204

Browse files
committed
Recursion as default for s3 List op, PrefixFolders to disable
1 parent 4eedfbd commit 77fb204

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

backends/s3/s3.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ type Options struct {
5555
// seamlessly
5656
GlobalPrefix string `yaml:"global_prefix"`
5757

58-
// Recursive can be enabled to make List operations recurse into nested prefixes
59-
Recursive bool `yaml:"recursive"`
58+
// PrefixFolders can be enabled to make List operations show nested prefixes as folders
59+
// instead of recursively listing all contents of nested prefixes
60+
PrefixFolders bool `yaml:"prefix_folders"`
6061

6162
// EndpointURL can be set to something like "http://localhost:9000" when using Minio
6263
// or "https://s3.amazonaws.com" for AWS S3.
@@ -165,7 +166,7 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
165166

166167
objCh := b.client.ListObjects(ctx, b.opt.Bucket, minio.ListObjectsOptions{
167168
Prefix: prefix,
168-
Recursive: b.opt.Recursive,
169+
Recursive: !b.opt.PrefixFolders,
169170
})
170171
for obj := range objCh {
171172
// Handle error returned by MinIO client

backends/s3/s3_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,24 @@ func TestBackend_recursive(t *testing.T) {
132132
err = b.Store(ctx, "foo/bar-3", []byte("bar3"))
133133
assert.NoError(t, err)
134134

135-
// List all - no recursion (default)
135+
// List all - PrefixFolders disabled (default)
136136
ls, err = b.List(ctx, "")
137137
assert.NoError(t, err)
138-
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2", "foo/"})
138+
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2", "foo/bar-3"})
139139

140-
// List all - recursive enabled
141-
b.opt.Recursive = true
140+
// List all - PrefixFolders enabled
141+
b.opt.PrefixFolders = true
142142

143143
ls, err = b.List(ctx, "")
144144
assert.NoError(t, err)
145-
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2", "foo/bar-3"})
145+
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2", "foo/"})
146146

147-
// List all - recursive disabled
148-
b.opt.Recursive = false
147+
// List all - PrefixFolders disabled
148+
b.opt.PrefixFolders = false
149149

150150
ls, err = b.List(ctx, "")
151151
assert.NoError(t, err)
152-
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2", "foo/"})
152+
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2", "foo/bar-3"})
153153

154154
assert.Len(t, b.lastMarker, 0)
155155
}

0 commit comments

Comments
 (0)