From d9d3a1605177cf7fcea6fa77164cafa328d667cd Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Tue, 17 Sep 2024 21:30:50 -0700 Subject: [PATCH] fix: azure list objects trim common prefixes that match marker prefix --- backend/azure/azure.go | 16 ++++++++++++++-- tests/integration/tests.go | 4 ++-- tests/integration/utils.go | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/backend/azure/azure.go b/backend/azure/azure.go index 53cc92e..c0c13cd 100644 --- a/backend/azure/azure.go +++ b/backend/azure/azure.go @@ -567,14 +567,19 @@ Pager: isTruncated = true break Pager } + + marker := getString(input.Marker) + pfx := strings.TrimSuffix(*v.Name, getString(input.Delimiter)) + if marker != "" && strings.HasPrefix(marker, pfx) { + continue + } + cPrefixes = append(cPrefixes, types.CommonPrefix{ Prefix: v.Name, }) } } - // TODO: generate common prefixes when appropriate - return s3response.ListObjectsResult{ Contents: objects, Marker: input.Marker, @@ -644,6 +649,13 @@ Pager: isTruncated = true break Pager } + + marker := getString(input.ContinuationToken) + pfx := strings.TrimSuffix(*v.Name, getString(input.Delimiter)) + if marker != "" && strings.HasPrefix(marker, pfx) { + continue + } + cPrefixes = append(cPrefixes, types.CommonPrefix{ Prefix: v.Name, }) diff --git a/tests/integration/tests.go b/tests/integration/tests.go index 4e4ebb1..016d6b3 100644 --- a/tests/integration/tests.go +++ b/tests/integration/tests.go @@ -3605,12 +3605,12 @@ func ListObjects_paginated(s *S3Conf) error { expected := []string{"dir1/subdir.ext", "dir1/subdir1.ext", "dir1/subdir2.ext"} if !hasObjNames(objs, expected) { - return fmt.Errorf("expected objects %v, instead got %v", expected, objs) + return fmt.Errorf("expected objects %v, instead got %v", expected, objStrings(objs)) } expectedPrefix := []string{"dir1/subdir/"} if !hasPrefixName(prefixes, expectedPrefix) { - return fmt.Errorf("expected prefixes %v, instead got %v", expectedPrefix, prefixes) + return fmt.Errorf("expected prefixes %v, instead got %v", expectedPrefix, pfxStrings(prefixes)) } return nil diff --git a/tests/integration/utils.go b/tests/integration/utils.go index a7ecca2..2f6c01b 100644 --- a/tests/integration/utils.go +++ b/tests/integration/utils.go @@ -844,3 +844,19 @@ func checkWORMProtection(client *s3.Client, bucket, object string) error { return nil } + +func objStrings(objs []types.Object) []string { + objStrs := make([]string, len(objs)) + for i, obj := range objs { + objStrs[i] = *obj.Key + } + return objStrs +} + +func pfxStrings(pfxs []types.CommonPrefix) []string { + pfxStrs := make([]string, len(pfxs)) + for i, pfx := range pfxs { + pfxStrs[i] = *pfx.Prefix + } + return pfxStrs +}