store all sha256 blobs in same dir

Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
pull/5243/head
Josh Dolitsky 7 years ago
parent 8bd056dbe3
commit 709a16687b

@ -109,6 +109,8 @@ func (cache *filesystemCache) ChartToLayers(ch *chart.Chart) ([]ocispec.Descript
// Create content layer // Create content layer
// TODO: something better than this hack. Currently needed for chartutil.Save() // TODO: something better than this hack. Currently needed for chartutil.Save()
// If metadata does not contain Name or Version, an error is returned
// such as "no chart name specified (Chart.yaml)"
ch.Metadata = &chart.Metadata{Name: "-", Version: "-"} ch.Metadata = &chart.Metadata{Name: "-", Version: "-"}
destDir := mkdir(filepath.Join(cache.rootDir, "blobs", ".build")) destDir := mkdir(filepath.Join(cache.rootDir, "blobs", ".build"))
tmpFile, err := chartutil.Save(ch, destDir) tmpFile, err := chartutil.Save(ch, destDir)
@ -187,7 +189,7 @@ func (cache *filesystemCache) StoreReference(ref *Reference, layers []ocispec.De
} }
// Save meta blob // Save meta blob
metaExists, metaPath := digestPath(filepath.Join(cache.rootDir, "blobs", "meta"), metaLayer.Digest) metaExists, metaPath := digestPath(filepath.Join(cache.rootDir, "blobs"), metaLayer.Digest)
if !metaExists { if !metaExists {
fmt.Fprintf(cache.out, "%s: Saving meta (%s)\n", fmt.Fprintf(cache.out, "%s: Saving meta (%s)\n",
shortDigest(metaLayer.Digest.Hex()), byteCountBinary(metaLayer.Size)) shortDigest(metaLayer.Digest.Hex()), byteCountBinary(metaLayer.Size))
@ -208,7 +210,7 @@ func (cache *filesystemCache) StoreReference(ref *Reference, layers []ocispec.De
} }
// Save content blob // Save content blob
contentExists, contentPath := digestPath(filepath.Join(cache.rootDir, "blobs", "content"), contentLayer.Digest) contentExists, contentPath := digestPath(filepath.Join(cache.rootDir, "blobs"), contentLayer.Digest)
if !contentExists { if !contentExists {
fmt.Fprintf(cache.out, "%s: Saving content (%s)\n", fmt.Fprintf(cache.out, "%s: Saving content (%s)\n",
shortDigest(contentLayer.Digest.Hex()), byteCountBinary(contentLayer.Size)) shortDigest(contentLayer.Digest.Hex()), byteCountBinary(contentLayer.Size))
@ -365,8 +367,7 @@ func createChartFile(chartsRootDir string, name string, version string) (string,
// digestPath returns the path to addressable content, and whether the file exists // digestPath returns the path to addressable content, and whether the file exists
func digestPath(rootDir string, digest checksum.Digest) (bool, string) { func digestPath(rootDir string, digest checksum.Digest) (bool, string) {
digestLeft, digestRight := splitDigest(digest.Hex()) path := filepath.Join(rootDir, "sha256", digest.Hex())
path := filepath.Join(rootDir, "sha256", digestLeft, digestRight)
exists := fileExists(path) exists := fileExists(path)
return exists, path return exists, path
} }
@ -377,17 +378,6 @@ func writeFile(path string, c []byte) error {
return ioutil.WriteFile(path, c, 0644) return ioutil.WriteFile(path, c, 0644)
} }
// splitDigest returns a sha256 digest in two parts, on with first 2 chars and one with second 62 chars
func splitDigest(digest string) (string, string) {
var digestLeft, digestRight string
digest = strings.TrimPrefix(digest, "sha256:")
if len(digest) == 64 {
digestLeft = digest[0:2]
digestRight = digest[2:64]
}
return digestLeft, digestRight
}
// byteCountBinary produces a human-readable file size // byteCountBinary produces a human-readable file size
func byteCountBinary(b int64) string { func byteCountBinary(b int64) string {
const unit = 1024 const unit = 1024
@ -450,10 +440,9 @@ func getRefsSorted(refsRootDir string) ([][]string, error) {
refsMap[ref]["name"] = filepath.Base(filepath.Dir(filepath.Dir(linkPath))) refsMap[ref]["name"] = filepath.Base(filepath.Dir(filepath.Dir(linkPath)))
refsMap[ref]["version"] = destFileInfo.Name() refsMap[ref]["version"] = destFileInfo.Name()
case "content": case "content":
shaPrefix := filepath.Base(filepath.Dir(linkPath))
digest := fmt.Sprintf("%s%s", shaPrefix, destFileInfo.Name())
// Make sure the filename looks like a sha256 digest (64 chars) // Make sure the filename looks like a sha256 digest (64 chars)
digest := destFileInfo.Name()
if len(digest) == 64 { if len(digest) == 64 {
refsMap[ref]["digest"] = shortDigest(digest) refsMap[ref]["digest"] = shortDigest(digest)
refsMap[ref]["size"] = byteCountBinary(destFileInfo.Size()) refsMap[ref]["size"] = byteCountBinary(destFileInfo.Size())

Loading…
Cancel
Save