Skip to content

Commit

Permalink
chore: drop semicolon for supporting vfat filesystems
Browse files Browse the repository at this point in the history
Drop semicolon in generated cache to support copying image cache to vfat
filesystems.

Fixes: #9935

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed Dec 12, 2024
1 parent 3e9e027 commit 136b129
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -191,7 +192,9 @@ func (svc *Service) resolveCanonicalRef(p params) (reference.Canonical, error) {
return nil, xerrors.NewTaggedf[internalErrorTag]("failed to hash manifest: %w", err)
}

sha256file := filepath.Join("manifests", namedTagged.Name(), "digest", digest.NewDigestFromBytes(digest.SHA256, ntSum).String())
digestString := strings.ReplaceAll(digest.NewDigestFromBytes(digest.SHA256, ntSum).String(), "sha256:", "sha256-")

sha256file := filepath.Join("manifests", namedTagged.Name(), "digest", digestString)

sSum, err := hashFile(sha256file, svc.root)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/app/machined/pkg/system/services/registry/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -101,7 +102,7 @@ func (s *singleFileStore) blobPath(dgst digest.Digest) (string, error) {
return "", fmt.Errorf("cannot calculate blob path from invalid digest: %v: %w", err, errdefs.ErrInvalidArgument)
}

return filepath.Join(s.path, dgst.String()), nil
return filepath.Join(s.path, strings.ReplaceAll(dgst.String(), "sha256:", "sha256-")), nil
}

var errUnimplemented = errors.New("unimplemented")
Expand Down
7 changes: 5 additions & 2 deletions internal/integration/cli/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"testing"

"github.com/siderolabs/gen/xslices"
"github.com/stretchr/testify/assert"

"github.com/siderolabs/talos/internal/integration/base"
"github.com/siderolabs/talos/pkg/machinery/config/machine"
Expand Down Expand Up @@ -87,13 +88,15 @@ func (suite *ImageSuite) TestCacheCreate() {
return "--images=" + image
})

cacheFile := suite.T().TempDir() + "/cache.tar"
cacheDir := suite.T().TempDir()

args := []string{"image", "cache-create", "--image-cache-path", cacheFile}
args := []string{"image", "cache-create", "--image-cache-path", cacheDir}

args = append(args, imagesArgs...)

suite.RunCLI(args, base.StdoutEmpty(), base.StderrNotEmpty())

assert.FileExistsf(suite.T(), cacheDir+"/index.json", "index.json should exist in the image cache directory")
}

func init() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/imager/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func Generate(images []string, platform string, insecure bool, imageLayerCachePa
}
}

if err := os.WriteFile(filepath.Join(digestDir, rmt.Digest.String()), manifest, 0o644); err != nil {
if err := os.WriteFile(filepath.Join(digestDir, strings.ReplaceAll(rmt.Digest.String(), "sha256:", "sha256-")), manifest, 0o644); err != nil {
return err
}

Expand Down Expand Up @@ -182,7 +182,7 @@ func Generate(images []string, platform string, insecure bool, imageLayerCachePa
return fmt.Errorf("platform manifest hash: %w", err)
}

if err := os.WriteFile(filepath.Join(digestDir, fmt.Sprintf("sha256:%x", h.Sum(nil))), platformManifest, 0o644); err != nil {
if err := os.WriteFile(filepath.Join(digestDir, fmt.Sprintf("sha256-%x", h.Sum(nil))), platformManifest, 0o644); err != nil {
return err
}

Expand All @@ -191,7 +191,7 @@ func Generate(images []string, platform string, insecure bool, imageLayerCachePa
return fmt.Errorf("getting image config hash: %w", err)
}

if err := os.WriteFile(filepath.Join(tmpDir, blobsDir, configHash.String()), config, 0o644); err != nil {
if err := os.WriteFile(filepath.Join(tmpDir, blobsDir, strings.ReplaceAll(configHash.String(), "sha256:", "sha256-")), config, 0o644); err != nil {
return err
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func processLayer(layer v1.Layer, dstDir string) error {
return fmt.Errorf("getting layer digest: %w", err)
}

blobPath := filepath.Join(dstDir, blobsDir, digest.String())
blobPath := filepath.Join(dstDir, blobsDir, strings.ReplaceAll(digest.String(), "sha256:", "sha256-"))

if _, err := os.Stat(blobPath); err == nil {
// we already have this blob, skip it
Expand Down

0 comments on commit 136b129

Please sign in to comment.