From 4accc8f2beed4df6022e9359b639a39dfc6cec56 Mon Sep 17 00:00:00 2001 From: Kira Date: Wed, 16 Nov 2016 16:35:24 +0800 Subject: [PATCH] filter listResponse.Contents in driver.List() Signed-off-by: Kira --- registry/storage/driver/oss/oss.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/registry/storage/driver/oss/oss.go b/registry/storage/driver/oss/oss.go index 4d215928..9797f42d 100644 --- a/registry/storage/driver/oss/oss.go +++ b/registry/storage/driver/oss/oss.go @@ -351,7 +351,8 @@ func (d *driver) List(ctx context.Context, opath string) ([]string, error) { prefix = "/" } - listResponse, err := d.Bucket.List(d.ossPath(path), "/", "", listMax) + ossPath := d.ossPath(path) + listResponse, err := d.Bucket.List(ossPath, "/", "", listMax) if err != nil { return nil, parseError(opath, err) } @@ -369,7 +370,7 @@ func (d *driver) List(ctx context.Context, opath string) ([]string, error) { } if listResponse.IsTruncated { - listResponse, err = d.Bucket.List(d.ossPath(path), "/", listResponse.NextMarker, listMax) + listResponse, err = d.Bucket.List(ossPath, "/", listResponse.NextMarker, listMax) if err != nil { return nil, err } @@ -378,6 +379,11 @@ func (d *driver) List(ctx context.Context, opath string) ([]string, error) { } } + // This is to cover for the cases when the first key equal to ossPath. + if len(files) > 0 && files[0] == strings.Replace(ossPath, d.ossPath(""), prefix, 1) { + files = files[1:] + } + if opath != "/" { if len(files) == 0 && len(directories) == 0 { // Treat empty response as missing directory, since we don't actually