6
6
"context"
7
7
"encoding/json"
8
8
"io"
9
+ "path"
9
10
10
11
"github.com/base-org/blob-archiver/common/flags"
11
12
"github.com/ethereum/go-ethereum/common"
@@ -17,7 +18,7 @@ import (
17
18
type S3Storage struct {
18
19
s3 * minio.Client
19
20
bucket string
20
- path string
21
+ path string
21
22
log log.Logger
22
23
compress bool
23
24
}
@@ -49,7 +50,7 @@ func NewS3Storage(cfg flags.S3Config, l log.Logger) (*S3Storage, error) {
49
50
}
50
51
51
52
func (s * S3Storage ) Exists (ctx context.Context , hash common.Hash ) (bool , error ) {
52
- _ , err := s .s3 .StatObject (ctx , s .bucket , s .path + hash .String (), minio.StatObjectOptions {})
53
+ _ , err := s .s3 .StatObject (ctx , s .bucket , path . Join ( s .path , hash .String () ), minio.StatObjectOptions {})
53
54
if err != nil {
54
55
errResponse := minio .ToErrorResponse (err )
55
56
if errResponse .Code == "NoSuchKey" {
@@ -63,7 +64,7 @@ func (s *S3Storage) Exists(ctx context.Context, hash common.Hash) (bool, error)
63
64
}
64
65
65
66
func (s * S3Storage ) Read (ctx context.Context , hash common.Hash ) (BlobData , error ) {
66
- res , err := s .s3 .GetObject (ctx , s .bucket , s .path + hash .String (), minio.GetObjectOptions {})
67
+ res , err := s .s3 .GetObject (ctx , s .bucket , path . Join ( s .path , hash .String () ), minio.GetObjectOptions {})
67
68
if err != nil {
68
69
s .log .Info ("unexpected error fetching blob" , "hash" , hash .String (), "err" , err )
69
70
return BlobData {}, ErrStorage
@@ -124,7 +125,7 @@ func (s *S3Storage) Write(ctx context.Context, data BlobData) error {
124
125
125
126
reader := bytes .NewReader (b )
126
127
127
- _ , err = s .s3 .PutObject (ctx , s .bucket , s .path + data .Header .BeaconBlockHash .String (), reader , int64 (len (b )), options )
128
+ _ , err = s .s3 .PutObject (ctx , s .bucket , path . Join ( s .path , data .Header .BeaconBlockHash .String () ), reader , int64 (len (b )), options )
128
129
129
130
if err != nil {
130
131
s .log .Warn ("error writing blob" , "err" , err )
0 commit comments