@@ -33,7 +33,7 @@ type bundleStore interface {
3333 putStream (ctx context.Context , commit , cacheKey string , r io.Reader ) (int64 , error )
3434}
3535
36- func newStore (bucket , region , cachewURL string ) (bundleStore , error ) {
36+ func newStore (bucket , region , cachewURL , keyPrefix string ) (bundleStore , error ) {
3737 if cachewURL != "" {
3838 return newCachewClient (cachewURL ), nil
3939 }
@@ -46,42 +46,47 @@ func newStore(bucket, region, cachewURL string) (bundleStore, error) {
4646 if err != nil {
4747 return nil , err
4848 }
49- return & s3BundleStore {client : client , bucket : bucket }, nil
49+ return & s3BundleStore {client : client , bucket : bucket , keyPrefix : keyPrefix }, nil
5050}
5151
5252// ── S3 bundle store ─────────────────────────────────────────────────────────
5353
5454type s3BundleStore struct {
55- client * s3Client
56- bucket string
55+ client * s3Client
56+ bucket string
57+ keyPrefix string // optional path prefix prepended to all object keys
5758}
5859
5960func (s * s3BundleStore ) stat (ctx context.Context , commit , cacheKey string ) (bundleStatInfo , error ) {
60- obj , err := s .client .stat (ctx , s .bucket , s3Key (commit , cacheKey , bundleFilename (cacheKey )))
61+ obj , err := s .client .stat (ctx , s .bucket , s3Key (s . keyPrefix , commit , cacheKey , bundleFilename (cacheKey )))
6162 if err != nil {
6263 return bundleStatInfo {}, err
6364 }
6465 return bundleStatInfo {Size : obj .Size , etag : obj .ETag }, nil
6566}
6667
6768func (s * s3BundleStore ) get (ctx context.Context , commit , cacheKey string , info bundleStatInfo ) (io.ReadCloser , error ) {
68- return s .client .get (ctx , s .bucket , s3Key (commit , cacheKey , bundleFilename (cacheKey )), s3ObjInfo {Size : info .Size , ETag : info .etag })
69+ return s .client .get (ctx , s .bucket , s3Key (s . keyPrefix , commit , cacheKey , bundleFilename (cacheKey )), s3ObjInfo {Size : info .Size , ETag : info .etag })
6970}
7071
7172func (s * s3BundleStore ) put (ctx context.Context , commit , cacheKey string , r io.ReadSeeker , size int64 ) error {
72- return s .client .put (ctx , s .bucket , s3Key (commit , cacheKey , bundleFilename (cacheKey )), r , size , "application/zstd" )
73+ return s .client .put (ctx , s .bucket , s3Key (s . keyPrefix , commit , cacheKey , bundleFilename (cacheKey )), r , size , "application/zstd" )
7374}
7475
7576func (s * s3BundleStore ) putStream (ctx context.Context , commit , cacheKey string , r io.Reader ) (int64 , error ) {
76- return s .client .putStreamingMultipart (ctx , s .bucket , s3Key (commit , cacheKey , bundleFilename (cacheKey )), r , "application/zstd" )
77+ return s .client .putStreamingMultipart (ctx , s .bucket , s3Key (s . keyPrefix , commit , cacheKey , bundleFilename (cacheKey )), r , "application/zstd" )
7778}
7879
7980func bundleFilename (cacheKey string ) string {
8081 return strings .ReplaceAll (cacheKey , ":" , "-" ) + ".tar.zst"
8182}
8283
83- func s3Key (commit , cacheKey , bundleFile string ) string {
84- return commit + "/" + cacheKey + "/" + bundleFile
84+ func s3Key (prefix , commit , cacheKey , bundleFile string ) string {
85+ key := commit + "/" + cacheKey + "/" + bundleFile
86+ if prefix != "" {
87+ return prefix + "/" + key
88+ }
89+ return key
8590}
8691
8792// ── Cachew client ───────────────────────────────────────────────────────────
0 commit comments