Skip to content

Commit

Permalink
add list with delimiter api
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Jun 27, 2022
1 parent f0c9b0d commit 61944df
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/object/cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func (c *COS) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (c *COS) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

func (c *COS) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/ibmcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func (s *ibmcos) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (s *ibmcos) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

func (s *ibmcos) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/object/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type ObjectStorage interface {
// ListAll returns all the objects as an channel.
ListAll(prefix, marker string) (<-chan Object, error)

ListWithDelimiter(prefix, delimiter string) ([]Object, error)

// CreateMultipartUpload starts to upload a large object part by part.
CreateMultipartUpload(key string) (*MultipartUpload, error)
// UploadPart upload a part of an object.
Expand Down
19 changes: 19 additions & 0 deletions pkg/object/ks3.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ func (s *ks3) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (s *ks3) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
param := s3.ListObjectsInput{
Bucket: &s.bucket,
Prefix: &prefix,
Delimiter: &delimiter,
}
resp, err := s.s3.ListObjects(&param)
if err != nil {
return nil, err
}
n := len(resp.Contents)
objs := make([]Object, n)
for i := 0; i < n; i++ {
o := resp.Contents[i]
objs[i] = &obj{*o.Key, *o.Size, *o.LastModified, strings.HasSuffix(*o.Key, "/")}
}
return objs, nil
}

func (s *ks3) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/object_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func (s DefaultObjectStorage) ListAll(prefix, marker string) (<-chan Object, err
return nil, notSupported
}

func (s DefaultObjectStorage) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

type Creator func(bucket, accessKey, secretKey, token string) (ObjectStorage, error)

var storages = make(map[string]Creator)
Expand Down
20 changes: 20 additions & 0 deletions pkg/object/obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ func (s *obsClient) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (s *obsClient) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
input := &obs.ListObjectsInput{
Bucket: s.bucket,
}
input.Prefix = prefix
input.MaxKeys = 1000
input.Delimiter = delimiter
resp, err := s.c.ListObjects(input)
if err != nil {
return nil, err
}
n := len(resp.Contents)
objs := make([]Object, n)
for i := 0; i < n; i++ {
o := resp.Contents[i]
objs[i] = &obj{o.Key, o.Size, o.LastModified, strings.HasSuffix(o.Key, "/")}
}
return objs, nil
}

func (s *obsClient) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (o *ossClient) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (o *ossClient) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

func (o *ossClient) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (p *withPrefix) List(prefix, marker string, limit int64) ([]Object, error)
return objs, err
}

func (p *withPrefix) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return p.os.ListWithDelimiter(p.prefix+prefix, delimiter)
}

func (p *withPrefix) ListAll(prefix, marker string) (<-chan Object, error) {
if marker != "" {
marker = p.prefix + marker
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/qingstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ func (q *qingstor) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (s *qingstor) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

func (q *qingstor) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func (s *s3client) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (s *s3client) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

func (s *s3client) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/scs.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (s *scsClient) List(prefix, marker string, limit int64) ([]Object, error) {
return objs, nil
}

func (s *scsClient) ListWithDelimiter(prefix, delimiter string) ([]Object, error) {
return nil, notSupported
}

func (s *scsClient) ListAll(prefix, marker string) (<-chan Object, error) {
return nil, notSupported
}
Expand Down

0 comments on commit 61944df

Please sign in to comment.