diff --git a/pkg/miniogw/gateway-storj.go b/pkg/miniogw/gateway-storj.go index da4d8aab5..3fd3e2d3c 100644 --- a/pkg/miniogw/gateway-storj.go +++ b/pkg/miniogw/gateway-storj.go @@ -206,26 +206,32 @@ func (s *storjObjects) ListObjects(ctx context.Context, bucket, prefix, marker, } startAfter := paths.New(marker) + recursive := delimiter == "" + var objects []minio.ObjectInfo var prefixes []string o, err := s.storj.bs.GetObjectStore(ctx, bucket) if err != nil { return minio.ListObjectsInfo{}, err } - items, more, err := o.List(ctx, paths.New(prefix), startAfter, nil, delimiter == "", maxKeys, meta.All) + items, more, err := o.List(ctx, paths.New(prefix), startAfter, nil, recursive, maxKeys, meta.All) if err != nil { return result, err } if len(items) > 0 { for _, item := range items { + path := item.Path + if recursive { + path = path.Prepend(prefix) + } if item.IsPrefix { - prefixes = append(prefixes, item.Path.String()+"/") + prefixes = append(prefixes, path.String()+"/") continue } objects = append(objects, minio.ObjectInfo{ Bucket: bucket, IsDir: false, - Name: item.Path.String(), + Name: path.String(), ModTime: item.Meta.Modified, Size: item.Meta.Size, ContentType: item.Meta.ContentType, diff --git a/pkg/miniogw/gateway-storj_test.go b/pkg/miniogw/gateway-storj_test.go index 7427e2737..7809969be 100644 --- a/pkg/miniogw/gateway-storj_test.go +++ b/pkg/miniogw/gateway-storj_test.go @@ -356,24 +356,37 @@ func TestListObjects(t *testing.T) { {Path: paths.New("test-file-2.txt")}, } - objInfos := []minio.ObjectInfo{ - {Bucket: bucket, Name: path.Join("test-file-1.txt")}, - {Bucket: bucket, Name: path.Join("test-file-2.txt")}, - } - for i, example := range []struct { more bool startAfter string nextMarker string delimiter string recursive bool + objInfos []minio.ObjectInfo err error errString string }{ - {false, "", "", "", true, nil, ""}, - {true, "test-start-after", "test-file-2.txt", "/", false, nil, ""}, - // mock returning non-nil error - {false, "", "", "", true, Error.New("error"), "Storj Gateway error: error"}, + { + more: false, startAfter: "", nextMarker: "", delimiter: "", recursive: true, + objInfos: []minio.ObjectInfo{ + {Bucket: bucket, Name: path.Join("test-prefix/test-file-1.txt")}, + {Bucket: bucket, Name: path.Join("test-prefix/test-file-2.txt")}, + }, err: nil, errString: "", + }, + { + more: true, startAfter: "test-start-after", nextMarker: "test-file-2.txt", delimiter: "/", recursive: false, + objInfos: []minio.ObjectInfo{ + {Bucket: bucket, Name: path.Join("test-file-1.txt")}, + {Bucket: bucket, Name: path.Join("test-file-2.txt")}, + }, err: nil, errString: "", + }, + { + more: false, startAfter: "", nextMarker: "", delimiter: "", recursive: true, + objInfos: []minio.ObjectInfo{ + {Bucket: bucket, Name: path.Join("test-prefix/test-file-1.txt")}, + {Bucket: bucket, Name: path.Join("test-prefix/test-file-2.txt")}, + }, err: Error.New("error"), errString: "Storj Gateway error: error", + }, } { errTag := fmt.Sprintf("Test case #%d", i) @@ -393,7 +406,7 @@ func TestListObjects(t *testing.T) { assert.NotNil(t, listInfo, errTag) assert.Equal(t, example.more, listInfo.IsTruncated, errTag) assert.Equal(t, example.nextMarker, listInfo.NextMarker, errTag) - assert.Equal(t, objInfos, listInfo.Objects, errTag) + assert.Equal(t, example.objInfos, listInfo.Objects, errTag) assert.Nil(t, listInfo.Prefixes, errTag) } }