Skip to content

Commit

Permalink
S3: list-objects to return all virtual subdirectories
Browse files Browse the repository at this point in the history
* when listing with `apc.LsNoRecursion` flag (CLI `--non-recursive`)

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
VladimirMarkelov authored and alex-aizman committed Jun 27, 2024
1 parent f72fc7d commit 0b14d0e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ais/backend/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0b14d0e

Please sign in to comment.