From 7f4eadaa031a65965ec2133ac92537c025a3fdda Mon Sep 17 00:00:00 2001 From: Michael Habinsky Date: Mon, 23 Oct 2023 16:20:45 -0600 Subject: [PATCH] Strip trailing slashes from both to compare. Add test. --- component/s3storage/client_test.go | 9 +++++++++ component/s3storage/s3wrappers.go | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/component/s3storage/client_test.go b/component/s3storage/client_test.go index b2d2a42fc..ab1e4157c 100644 --- a/component/s3storage/client_test.go +++ b/component/s3storage/client_test.go @@ -645,6 +645,15 @@ func (s *clientTestSuite) TestList() { s.assert.EqualValues(len(objects), 1) s.assert.EqualValues(objects[0].Name, base+"c") s.assert.False(objects[0].IsDir()) + + // When listing the root, List should not include the root + objects, _, err = s.client.List("", nil, 0) + s.assert.Nil(err) + s.assert.NotNil(objects) + s.assert.Greater(len(objects), 0) + s.assert.NotEqual(objects[0].Name, "") + s.assert.NotEqual(objects[0].Name, "/") + s.assert.NotEqual(objects[0].Name, ".") } func (s *clientTestSuite) TestReadToFile() { defer s.cleanupTest() diff --git a/component/s3storage/s3wrappers.go b/component/s3storage/s3wrappers.go index b57c6a421..d21eaac74 100644 --- a/component/s3storage/s3wrappers.go +++ b/component/s3storage/s3wrappers.go @@ -404,8 +404,7 @@ func (cl *Client) List(prefix string, marker *string, count int32) ([]*internal. // now let's add attributes for all the directories in dirList for dir := range dirList { dirName, _ := cl.getFile(dir) - dirName = internal.TruncateDirName(dirName) - if dirName == listPath { + if internal.TruncateDirName(dirName) == internal.TruncateDirName(listPath) { continue } path := split(cl.Config.prefixPath, dirName)