mirror of
https://github.com/minio/minio.git
synced 2025-01-24 05:03:16 -05:00
Support marker, closes #4286
This commit is contained in:
parent
2de1921fe8
commit
f3e5e9fb29
@ -33,6 +33,8 @@ import (
|
||||
"google.golang.org/api/googleapi"
|
||||
"google.golang.org/api/iterator"
|
||||
|
||||
"encoding/base64"
|
||||
|
||||
minio "github.com/minio/minio-go"
|
||||
"github.com/minio/minio-go/pkg/policy"
|
||||
)
|
||||
@ -274,6 +276,24 @@ func (l *gcsGateway) DeleteBucket(bucket string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func toGCSPageToken(name string) string {
|
||||
length := uint16(len(name))
|
||||
|
||||
b := []byte{
|
||||
0xa,
|
||||
byte(length & 0xFF),
|
||||
}
|
||||
|
||||
length = length >> 7
|
||||
if length > 0 {
|
||||
b = append(b, byte(length&0xFF))
|
||||
}
|
||||
|
||||
b = append(b, []byte(name)...)
|
||||
|
||||
return base64.StdEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
// ListObjects - lists all blobs in GCS bucket filtered by prefix
|
||||
func (l *gcsGateway) ListObjects(bucket string, prefix string, marker string, delimiter string, maxKeys int) (ListObjectsInfo, error) {
|
||||
it := l.client.Bucket(bucket).Objects(l.ctx, &storage.Query{Delimiter: delimiter, Prefix: prefix, Versions: false})
|
||||
@ -282,6 +302,11 @@ func (l *gcsGateway) ListObjects(bucket string, prefix string, marker string, de
|
||||
nextMarker := ""
|
||||
prefixes := []string{}
|
||||
|
||||
maxKeys = maxKeys
|
||||
|
||||
// we'll set marker to continue
|
||||
it.PageInfo().Token = marker
|
||||
|
||||
objects := []ObjectInfo{}
|
||||
for {
|
||||
if len(objects) >= maxKeys {
|
||||
@ -290,8 +315,6 @@ func (l *gcsGateway) ListObjects(bucket string, prefix string, marker string, de
|
||||
// metadata folder, then just break
|
||||
// otherwise we've truncated the output
|
||||
|
||||
m := it.PageInfo().Token
|
||||
|
||||
attrs, _ := it.Next()
|
||||
if attrs == nil {
|
||||
} else if attrs.Prefix == ZZZZMinioPrefix {
|
||||
@ -299,19 +322,18 @@ func (l *gcsGateway) ListObjects(bucket string, prefix string, marker string, de
|
||||
}
|
||||
|
||||
isTruncated = true
|
||||
nextMarker = m
|
||||
break
|
||||
}
|
||||
|
||||
attrs, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
} else if err != nil {
|
||||
return ListObjectsInfo{}, gcsToObjectError(traceError(err), bucket, prefix)
|
||||
}
|
||||
|
||||
nextMarker = toGCSPageToken(attrs.Name)
|
||||
|
||||
if attrs.Prefix == ZZZZMinioPrefix {
|
||||
// we don't return our metadata prefix
|
||||
continue
|
62
cmd/gateway-gcs_test.go
Normal file
62
cmd/gateway-gcs_test.go
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestToGCSPageToken(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Token string
|
||||
}{
|
||||
{
|
||||
Name: "A",
|
||||
Token: "CgFB",
|
||||
},
|
||||
{
|
||||
Name: "AAAAAAAAAA",
|
||||
Token: "CgpBQUFBQUFBQUFB",
|
||||
},
|
||||
{
|
||||
Name: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUE=",
|
||||
},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
if toGCSPageToken(testCase.Name) != testCase.Token {
|
||||
t.Errorf("Test %d: Expected %s, got %s", i+1, toGCSPageToken(testCase.Name), testCase.Token)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user