Skip to content

Commit 136b129

Browse files
committed
chore: drop semicolon for supporting vfat filesystems
Drop semicolon in generated cache to support copying image cache to vfat filesystems. Fixes: #9935 Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent 3e9e027 commit 136b129

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

internal/app/machined/pkg/system/services/registry/registry.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"os"
2020
"path/filepath"
2121
"strconv"
22+
"strings"
2223
"sync"
2324
"time"
2425

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

194-
sha256file := filepath.Join("manifests", namedTagged.Name(), "digest", digest.NewDigestFromBytes(digest.SHA256, ntSum).String())
195+
digestString := strings.ReplaceAll(digest.NewDigestFromBytes(digest.SHA256, ntSum).String(), "sha256:", "sha256-")
196+
197+
sha256file := filepath.Join("manifests", namedTagged.Name(), "digest", digestString)
195198

196199
sSum, err := hashFile(sha256file, svc.root)
197200
if err != nil {

internal/app/machined/pkg/system/services/registry/store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io/fs"
1212
"os"
1313
"path/filepath"
14+
"strings"
1415
"syscall"
1516
"time"
1617

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

104-
return filepath.Join(s.path, dgst.String()), nil
105+
return filepath.Join(s.path, strings.ReplaceAll(dgst.String(), "sha256:", "sha256-")), nil
105106
}
106107

107108
var errUnimplemented = errors.New("unimplemented")

internal/integration/cli/image.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/siderolabs/gen/xslices"
15+
"github.com/stretchr/testify/assert"
1516

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

90-
cacheFile := suite.T().TempDir() + "/cache.tar"
91+
cacheDir := suite.T().TempDir()
9192

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

9495
args = append(args, imagesArgs...)
9596

9697
suite.RunCLI(args, base.StdoutEmpty(), base.StderrNotEmpty())
98+
99+
assert.FileExistsf(suite.T(), cacheDir+"/index.json", "index.json should exist in the image cache directory")
97100
}
98101

99102
func init() {

pkg/imager/cache/cache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func Generate(images []string, platform string, insecure bool, imageLayerCachePa
149149
}
150150
}
151151

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)