[breaking-change] Split blob paths for S3 backend as well.

This commit is contained in:
Catherine
2025-09-17 10:03:39 +00:00
parent 373d48ed22
commit b3f8b941d8

View File

@@ -11,6 +11,7 @@ import (
"io"
"log"
"os"
"path"
"path/filepath"
"slices"
"strings"
@@ -50,6 +51,15 @@ type Backend interface {
DeleteManifest(name string) error
}
func splitBlobName(name string) []string {
algo, hash, found := strings.Cut(name, "-")
if found {
return slices.Concat([]string{algo}, splitBlobName(hash))
} else {
return []string{name[0:2], name[2:4], name[4:]}
}
}
type FSBackend struct {
blobRoot *os.Root
siteRoot *os.Root
@@ -105,15 +115,6 @@ func (fs *FSBackend) Backend() Backend {
return fs
}
func splitBlobName(name string) []string {
algo, hash, found := strings.Cut(name, "-")
if found {
return slices.Concat([]string{algo}, splitBlobName(hash))
} else {
return []string{name[0:2], name[2:4], name[4:]}
}
}
func (fs *FSBackend) GetBlob(name string) (io.ReadSeeker, time.Time, error) {
blobPath := filepath.Join(splitBlobName(name)...)
stat, err := fs.blobRoot.Stat(blobPath)
@@ -320,7 +321,7 @@ func (s3 *S3Backend) Backend() Backend {
}
func blobObjectName(name string) string {
return fmt.Sprintf("blob/%s", name)
return fmt.Sprintf("blob/%s", path.Join(splitBlobName(name)...))
}
func (s3 *S3Backend) GetBlob(name string) (io.ReadSeeker, time.Time, error) {