Skip to content

Commit

Permalink
go/runtime/bundle: Use manifest hash at bundle load time
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jul 23, 2024
1 parent 6e844a4 commit b98e8ef
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions go/runtime/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
type Bundle struct {
Manifest *Manifest
Data map[string][]byte

// manifestHash is the original manifest hash of the bundle at time the bundle was loaded.
manifestHash hash.Hash
}

// Validate validates the runtime bundle for well-formedness.
Expand Down Expand Up @@ -277,6 +280,9 @@ func (bnd *Bundle) Write(fn string) error {
return fmt.Errorf("runtime/bundle: failed to write bundle: %w", err)
}

// Update the manifest hash.
bnd.manifestHash = bnd.Manifest.Hash()

return nil
}

Expand All @@ -298,12 +304,12 @@ func (bnd *Bundle) ExplodedPath(dataDir, fn string) string {
case false:
// DATADIR/runtimes/bundles/manifestHash
subDir = filepath.Join(ExplodedPath(dataDir),
bnd.Manifest.Hash().String(),
bnd.manifestHash.String(),
)
case true:
// DATADIR/runtimes/bundles/detached/manifestHash
subDir = filepath.Join(DetachedExplodedPath(dataDir),
bnd.Manifest.Hash().String(),
bnd.manifestHash.String(),
)
}

Expand Down Expand Up @@ -378,6 +384,7 @@ func (bnd *Bundle) WriteExploded(dataDir string) error {
func (bnd *Bundle) Close() error {
bnd.Manifest = nil
bnd.Data = nil
bnd.manifestHash.Empty()
return nil
}

Expand Down Expand Up @@ -436,8 +443,9 @@ func Open(fn string) (*Bundle, error) {

// Ensure the bundle is well-formed.
bnd := &Bundle{
Manifest: &manifest,
Data: data,
Manifest: &manifest,
Data: data,
manifestHash: manifest.Hash(),
}
if err = bnd.Validate(); err != nil {
return nil, err
Expand Down

0 comments on commit b98e8ef

Please sign in to comment.