From 0b14d0ec37b1052e90b293dd3fea77877b3be476 Mon Sep 17 00:00:00 2001 From: Vladimir Markelov Date: Wed, 26 Jun 2024 20:34:01 -0400 Subject: [PATCH] S3: list-objects to return all virtual subdirectories * when listing with `apc.LsNoRecursion` flag (CLI `--non-recursive`) Signed-off-by: Alex Aizman --- ais/backend/aws.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ais/backend/aws.go b/ais/backend/aws.go index 28979b9158..63ad9723db 100644 --- a/ais/backend/aws.go +++ b/ais/backend/aws.go @@ -292,13 +292,10 @@ func (*s3bp) ListObjects(bck *meta.Bck, msg *apc.LsoMsg, lst *cmn.LsoRes) (ecode return 0, err } params := &s3.ListObjectsV2Input{Bucket: aws.String(cloudBck.Name)} + if msg.IsFlagSet(apc.LsNoRecursion) { + params.Delimiter = aws.String("/") + } if prefix := msg.Prefix; prefix != "" { - if msg.IsFlagSet(apc.LsNoRecursion) { - // NOTE: important to indicate subdirectory with trailing '/' - if cos.IsLastB(prefix, '/') { - params.Delimiter = aws.String("/") - } - } params.Prefix = aws.String(prefix) } if msg.ContinuationToken != "" { @@ -351,6 +348,13 @@ func (*s3bp) ListObjects(bck *meta.Bck, msg *apc.LsoMsg, lst *cmn.LsoRes) (ecode } lst.Entries = lst.Entries[:l] + // append virtual directories if: + if msg.IsFlagSet(apc.LsNoRecursion) { + for _, dir := range resp.CommonPrefixes { + lst.Entries = append(lst.Entries, &cmn.LsoEnt{Name: *dir.Prefix, Flags: apc.EntryIsDir}) + } + } + if *resp.IsTruncated { lst.ContinuationToken = *resp.NextContinuationToken }