From d245a2655179e1a5311220d22ddf6145aace22a0 Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Tue, 14 Jan 2025 13:14:34 +0100 Subject: [PATCH] Fixup: `ManifestName` rename and comment --- go/runtime/bundle/bundle.go | 14 +++++++------- go/runtime/bundle/bundle_test.go | 8 ++++---- go/runtime/bundle/discovery.go | 2 +- go/runtime/bundle/manifest.go | 5 +++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/go/runtime/bundle/bundle.go b/go/runtime/bundle/bundle.go index f50a57eb157..67e225c9431 100644 --- a/go/runtime/bundle/bundle.go +++ b/go/runtime/bundle/bundle.go @@ -135,7 +135,7 @@ func (bnd *Bundle) Validate() error { // Ignore the manifest not having a digest entry, though // it having one and being valid (while quite a feat) is // also ok. - if fn == ManifestName { + if fn == ManifestPath { continue } return fmt.Errorf("runtime/bundle: missing digest: '%s'", fn) @@ -321,7 +321,7 @@ func (bnd *Bundle) verifySgxSignature(comp *Component) error { // // This needs to be used after doing modifications to bundles. func (bnd *Bundle) ResetManifest() { - delete(bnd.Data, ManifestName) + delete(bnd.Data, ManifestPath) } // Write serializes a runtime bundle to the on-disk representation. @@ -336,7 +336,7 @@ func (bnd *Bundle) Write(fn string) error { if err != nil { return fmt.Errorf("runtime/bundle: failed to serialize manifest: %w", err) } - if bnd.Data[ManifestName] != nil { + if bnd.Data[ManifestPath] != nil { // While this is "ok", instead of trying to figure out if the // deserialized manifest matches the serialied one, just bail. return fmt.Errorf("runtime/bundle: data contains manifest entry") @@ -352,7 +352,7 @@ func (bnd *Bundle) Write(fn string) error { } writeFiles := []writeFile{ { - fn: ManifestName, + fn: ManifestPath, d: NewBytesData(rawManifest), }, } @@ -474,7 +474,7 @@ func (bnd *Bundle) WriteExploded(dataDir string) (string, error) { for _, v := range []string{ subDir, - bnd.ExplodedPath(dataDir, manifestPath), + bnd.ExplodedPath(dataDir, manifestMetadataSubdir), } { if err = os.MkdirAll(v, 0o700); err != nil { return "", fmt.Errorf("runtime/bundle: failed to create asset sub-dir '%s': %w", v, err) @@ -558,7 +558,7 @@ func Open(fn string, opts ...OpenOption) (_ *Bundle, err error) { switch i { case 0: // Much like the JAR files, the manifest MUST come first. - if v.Name != ManifestName { + if v.Name != ManifestPath { return nil, fmt.Errorf("runtime/bundle: invalid manifest file name: '%s'", v.Name) } default: @@ -572,7 +572,7 @@ func Open(fn string, opts ...OpenOption) (_ *Bundle, err error) { // Decode the manifest. var manifest Manifest - d, ok := data[ManifestName] + d, ok := data[ManifestPath] if !ok { return nil, fmt.Errorf("runtime/bundle: missing manifest") } diff --git a/go/runtime/bundle/bundle_test.go b/go/runtime/bundle/bundle_test.go index 54a78afa608..d2405d7b668 100644 --- a/go/runtime/bundle/bundle_test.go +++ b/go/runtime/bundle/bundle_test.go @@ -71,8 +71,8 @@ func TestBundle(t *testing.T) { // Ignore the manifest, the bundle we used to create the file // will not have it. - delete(bundle2.Manifest.Digests, ManifestName) - delete(bundle2.Data, ManifestName) + delete(bundle2.Manifest.Digests, ManifestPath) + delete(bundle2.Data, ManifestPath) ensureBundlesEqual(t, bundle, bundle2, "opened bundle mismatch") @@ -171,8 +171,8 @@ func TestDetachedBundle(t *testing.T) { // Ignore the manifest, the bundle we used to create the file // will not have it. - delete(bundle2.Manifest.Digests, ManifestName) - delete(bundle2.Data, ManifestName) + delete(bundle2.Manifest.Digests, ManifestPath) + delete(bundle2.Data, ManifestPath) ensureBundlesEqual(t, bundle, bundle2, "opened bundle mismatch") }) diff --git a/go/runtime/bundle/discovery.go b/go/runtime/bundle/discovery.go index 0cc46e6eafe..f3b780dca99 100644 --- a/go/runtime/bundle/discovery.go +++ b/go/runtime/bundle/discovery.go @@ -554,7 +554,7 @@ func (d *Discovery) cleanStaleExplodedBundles() { if len(manifestHash) != 2*hash.Size { continue } - manifestPath := filepath.Join(bundlesDir, manifestHash, ManifestName) + manifestPath := filepath.Join(bundlesDir, manifestHash, ManifestPath) data, err := os.ReadFile(manifestPath) if err != nil { d.logger.Error("error reading manifest file", diff --git a/go/runtime/bundle/manifest.go b/go/runtime/bundle/manifest.go index e16db74f58f..61df13d955d 100644 --- a/go/runtime/bundle/manifest.go +++ b/go/runtime/bundle/manifest.go @@ -10,8 +10,9 @@ import ( ) const ( - ManifestName = manifestPath + "/MANIFEST.MF" - manifestPath = "META-INF" + // ManifestPath is a relative path to manifest file inside a bundle. + ManifestPath = manifestMetadataSubdir + "/MANIFEST.MF" + manifestMetadataSubdir = "META-INF" ) // Manifest is a deserialized runtime bundle manifest.