From edad5b40c75b4524f934f5f110f7d1dcb53a1aba Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Sun, 3 Nov 2024 20:27:32 +0200 Subject: [PATCH] ensure that S3 Push does not double-slash at beginning Signed-off-by: Avi Deitcher --- pkg/storage/s3/s3.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/storage/s3/s3.go b/pkg/storage/s3/s3.go index 3bdb1745..e6f27936 100644 --- a/pkg/storage/s3/s3.go +++ b/pkg/storage/s3/s3.go @@ -7,6 +7,7 @@ import ( "net/url" "os" "path" + "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -113,10 +114,14 @@ func (s *S3) Push(target, source string, logger *log.Entry) (int64, error) { } defer f.Close() + // S3 always prepends a /, so if it already has one, it would become // + // For some services, that is ok, but for others, it causes issues. + key = strings.TrimPrefix(path.Join(key, target), "/") + // Write the contents of the file to the S3 object _, err = uploader.Upload(context.TODO(), &s3.PutObjectInput{ Bucket: aws.String(bucket), - Key: aws.String(path.Join(key, target)), + Key: aws.String(key), Body: f, }) if err != nil {