Skip to content

Commit 3db22a2

Browse files
authored
Rewind mode list directory bug fix (#1297)
* rewind bug fix * adding constant
1 parent 884321c commit 3db22a2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

restapi/client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func computeObjectURLWithoutEncode(bucketName, prefix string) (string, error) {
389389
objectURL = path.Join(objectURL, bucketName)
390390
}
391391
if strings.TrimSpace(prefix) != "" {
392-
objectURL = path.Join(objectURL, prefix)
392+
objectURL = pathJoinFinalSlash(objectURL, prefix)
393393
}
394394

395395
objectURL = fmt.Sprintf("%s://%s", u.Scheme, objectURL)
@@ -418,6 +418,16 @@ func newS3BucketClient(claims *models.Principal, bucketName string, prefix strin
418418
return s3Client, nil
419419
}
420420

421+
// pathJoinFinalSlash - like path.Join() but retains trailing slashSeparator of the last element
422+
func pathJoinFinalSlash(elem ...string) string {
423+
if len(elem) > 0 {
424+
if strings.HasSuffix(elem[len(elem)-1], SlashSeparator) {
425+
return path.Join(elem...) + SlashSeparator
426+
}
427+
}
428+
return path.Join(elem...)
429+
}
430+
421431
// newS3Config simply creates a new Config struct using the passed
422432
// parameters.
423433
func newS3Config(endpoint, accessKey, secretKey, sessionToken string, insecure bool) *mc.Config {

restapi/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ const (
5454
ConsoleLogQueryURL = "CONSOLE_LOG_QUERY_URL"
5555
ConsoleLogQueryAuthToken = "CONSOLE_LOG_QUERY_AUTH_TOKEN"
5656
LogSearchQueryAuthToken = "LOGSEARCH_QUERY_AUTH_TOKEN"
57+
SlashSeparator = "/"
5758
)

0 commit comments

Comments
 (0)