Join the S3 prefix to every key with one slash (closes #222)
check / check (push) Successful in 10m54s
check / check (push) Successful in 10m54s
The S3 client built each key as prefix + key, and the URL parser keeps the prefix as written, so s3://bucket/p stored p + "blobs/..." with no slash while s3://bucket/p/ stored p/blobs/.... A recovery host that wrote the URL the other way found no snapshots. NewClient now strips trailing slashes from the prefix and adds one back when anything is left, giving the README layout for both URL forms; an empty prefix stays at the bucket root. The s3.prefix config setting goes through the same client and gets the same join. A new test writes through each URL shape against an in-process S3 server, checks the key in the bucket, and lists through both List and ListStream, which every snapshot listing uses. Model: opus-5-5
This commit is contained in:
+11
-1
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
@@ -30,6 +31,8 @@ type Client struct {
|
||||
|
||||
// Config contains S3 client configuration.
|
||||
// All fields are required except Prefix, which defaults to an empty string.
|
||||
// A non-empty Prefix is joined to every key with one "/", whether or not
|
||||
// it ends with one.
|
||||
// The Endpoint field should include the protocol (http:// or https://).
|
||||
type Config struct {
|
||||
Endpoint string
|
||||
@@ -75,10 +78,17 @@ func NewClient(ctx context.Context, cfg Config) (*Client, error) {
|
||||
|
||||
s3Client := s3.NewFromConfig(awsCfg, s3Opts)
|
||||
|
||||
// Every method below builds a key as prefix + key, so the prefix
|
||||
// must carry its own trailing "/".
|
||||
prefix := strings.TrimRight(cfg.Prefix, "/")
|
||||
if prefix != "" {
|
||||
prefix += "/"
|
||||
}
|
||||
|
||||
return &Client{
|
||||
s3Client: s3Client,
|
||||
bucket: cfg.Bucket,
|
||||
prefix: cfg.Prefix,
|
||||
prefix: prefix,
|
||||
endpoint: cfg.Endpoint,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user