diff --git a/e2e/ls_test.go b/e2e/ls_test.go index 203b1cac9..4c60bb96f 100644 --- a/e2e/ls_test.go +++ b/e2e/ls_test.go @@ -786,3 +786,20 @@ func TestListNestedLocalFolders(t *testing.T) { 2: match(filepath.ToSlash("file.txt")), }, trimMatch(dateRe), alignment(true)) } + +// ls empty bucket +func TestEmptyBucket(t *testing.T) { + t.Parallel() + + s3client, s5cmd := setup(t) + + bucket := s3BucketFromTestName(t) + createBucket(t, s3client, bucket) + + cmd := s5cmd("ls", "s3://"+bucket) + result := icmd.RunCmd(cmd) + + result.Assert(t, icmd.Success) + + assertLines(t, result.Stdout(), map[int]compareFunc{}, alignment(true)) +} diff --git a/storage/s3.go b/storage/s3.go index f6ebcffd3..22546b61f 100644 --- a/storage/s3.go +++ b/storage/s3.go @@ -288,7 +288,7 @@ func (s *S3) listObjectVersions(ctx context.Context, url *url.URL) <-chan *Objec return } - if !objectFound { + if !objectFound && !url.IsBucket() { objCh <- &Object{Err: ErrNoObjectFound} } }() @@ -378,7 +378,7 @@ func (s *S3) listObjectsV2(ctx context.Context, url *url.URL) <-chan *Object { return } - if !objectFound { + if !objectFound && !url.IsBucket() { objCh <- &Object{Err: ErrNoObjectFound} } }() @@ -470,7 +470,7 @@ func (s *S3) listObjects(ctx context.Context, url *url.URL) <-chan *Object { return } - if !objectFound { + if !objectFound && !url.IsBucket() { objCh <- &Object{Err: ErrNoObjectFound} } }()