diff --git a/azblob/list.go b/azblob/list.go index 48f845c..d954b77 100644 --- a/azblob/list.go +++ b/azblob/list.go @@ -7,21 +7,27 @@ import ( azStorageBlob "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" - "github.com/datatrails/go-datatrails-common/logger" "github.com/datatrails/go-datatrails-common/tracing" ) // Count counts the number of blobs filtered by the given tags filter func (azp *Storer) Count(ctx context.Context, tagsFilter string, opts ...Option) (int64, error) { - logger.Sugar.Debugf("Count") - - r, err := azp.FilteredList(ctx, tagsFilter, opts...) - if err != nil { - return 0, err - } - - return int64(len(r.Items)), nil + var count int64 + var m ListMarker + + for { + r, err := azp.FilteredList(ctx, tagsFilter, append(opts, WithListMarker(m))...) + if err != nil { + return 0, err + } + count += int64(len(r.Items)) + if r.Marker == nil || *r.Marker == "" { + break + } + m = r.Marker + } + return count, nil } type FilterResponse struct { @@ -92,12 +98,11 @@ func (azp *Storer) FilteredList(ctx context.Context, tagsFilter string, opts ... Items: resp.Blobs, } - r.Marker = resp.NextMarker if r.Marker != nil { span.SetTag("nextmarker", *r.Marker) } - return r, err + return r, nil } type ListerResponse struct { diff --git a/azblob/logger.go b/azblob/logger.go new file mode 100644 index 0000000..22c99b7 --- /dev/null +++ b/azblob/logger.go @@ -0,0 +1,11 @@ +package azblob + +import ( + "github.com/datatrails/go-datatrails-common/logger" +) + +const ( + DebugLevel = logger.DebugLevel +) + +type Logger = logger.Logger diff --git a/azblob/storer.go b/azblob/storer.go index 51822fd..8aa582a 100644 --- a/azblob/storer.go +++ b/azblob/storer.go @@ -27,6 +27,8 @@ type Storer struct { containerURL string containerClient *ContainerClient serviceClient *ServiceClient + + log Logger } // New returns new az blob read/write object