@@ -106,23 +106,24 @@ func (o Options) Check() error {
106106}
107107
108108type Backend struct {
109- opt Options
110- config * minio.Options
111- client * minio.Client
112- log logr.Logger
109+ opt Options
110+ config * minio.Options
111+ client * minio.Client
112+ log logr.Logger
113+ markerName string
113114
114115 mu sync.Mutex
115116 lastMarker string
116117 lastList simpleblob.BlobList
117118 lastTime time.Time
118119}
119120
120- func (b * Backend ) List (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
121- // Prepend global prefix
122- prefix = b .prependGlobalPrefix (prefix )
121+ func (b * Backend ) List (ctx context.Context , prefix string ) (blobList simpleblob.BlobList , err error ) {
122+ // Handle global prefix
123+ combinedPrefix : = b .prependGlobalPrefix (prefix )
123124
124125 if ! b .opt .UseUpdateMarker {
125- return b .doList (ctx , prefix )
126+ return b .doList (ctx , combinedPrefix )
126127 }
127128
128129 m , err := b .Load (ctx , UpdateMarkerFilename )
@@ -144,7 +145,7 @@ func (b *Backend) List(ctx context.Context, prefix string) (simpleblob.BlobList,
144145 return blobs .WithPrefix (prefix ), nil
145146 }
146147
147- blobs , err = b .doList (ctx , "" ) // We want to cache all, so no prefix
148+ blobs , err = b .doList (ctx , b . opt . GlobalPrefix ) // We want to cache all, so no prefix
148149 if err != nil {
149150 return nil , err
150151 }
@@ -162,7 +163,9 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
162163 var blobs simpleblob.BlobList
163164
164165 // Runes to strip from blob names for GlobalPrefix
165- gpEndRune := len (b .opt .GlobalPrefix )
166+ // This is fine, because we can trust the API to only return with the prefix.
167+ // TODO: trust but verify
168+ gpEndIndex := len (b .opt .GlobalPrefix )
166169
167170 objCh := b .client .ListObjects (ctx , b .opt .Bucket , minio.ListObjectsOptions {
168171 Prefix : prefix ,
@@ -177,14 +180,14 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
177180
178181 metricCalls .WithLabelValues ("list" ).Inc ()
179182 metricLastCallTimestamp .WithLabelValues ("list" ).SetToCurrentTime ()
180- if obj .Key == UpdateMarkerFilename {
183+ if obj .Key == b . markerName {
181184 continue
182185 }
183186
184187 // Strip global prefix from blob
185188 blobName := obj .Key
186- if gpEndRune > 0 {
187- blobName = blobName [gpEndRune :]
189+ if gpEndIndex > 0 {
190+ blobName = blobName [gpEndIndex :]
188191 }
189192
190193 blobs = append (blobs , simpleblob.Blob {Name : blobName , Size : obj .Size })
@@ -378,10 +381,18 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
378381 client : client ,
379382 log : log ,
380383 }
384+ b .setGlobalPrefix (opt .GlobalPrefix )
381385
382386 return b , nil
383387}
384388
389+ // setGlobalPrefix updates the global prefix in b and the cached marker name,
390+ // so it can be dynamically changed in tests.
391+ func (b * Backend ) setGlobalPrefix (prefix string ) {
392+ b .opt .GlobalPrefix = prefix
393+ b .markerName = b .prependGlobalPrefix (UpdateMarkerFilename )
394+ }
395+
385396// convertMinioError takes an error, possibly a minio.ErrorResponse
386397// and turns it into a well known error when possible.
387398// If error is not well known, it is returned as is.
0 commit comments