diff --git a/go/runtime/bundle/discovery.go b/go/runtime/bundle/discovery.go index 0a90beae5bb..7842a782332 100644 --- a/go/runtime/bundle/discovery.go +++ b/go/runtime/bundle/discovery.go @@ -63,7 +63,7 @@ type Discovery struct { } // NewDiscovery creates a new bundle discovery. -func NewDiscovery(dataDir string, registry Registry, runtimeIDsCfg []common.Namespace) *Discovery { +func NewDiscovery(dataDir string, registry Registry, runtimeIDs []common.Namespace) *Discovery { logger := logging.GetLogger("runtime/bundle/discovery") client := http.Client{ @@ -527,7 +527,7 @@ func (d *Discovery) copyBundle(src string) error { // cleanStaleExplodedBundles removes regular and detached bundles exploded bundle subdir, // for the runtimes no longer present in the configuration. func (d *Discovery) cleanStaleExplodedBundles(ctx context.Context) { - d.logger.Info("removing exploded (regular and detached) bundles for runtimes no longer present in the config") + d.logger.Info("removing stale bundles") cleanDir := func(bundlesDir string) { entries, err := os.ReadDir(bundlesDir) @@ -535,9 +535,11 @@ func (d *Discovery) cleanStaleExplodedBundles(ctx context.Context) { if os.IsNotExist(err) { return } - d.logger.Error("error reading bundles dir", + d.logger.Error("failed to read bundles dir", "dir", bundlesDir, - "err", err) + "err", err, + ) + return } for _, entry := range entries { @@ -557,7 +559,7 @@ func (d *Discovery) cleanStaleExplodedBundles(ctx context.Context) { data, err := os.ReadFile(manifestPath) if err != nil { d.logger.Error("error reading manifest file", - "manifestHash", manifestHash, + "path", manifestPath, "err", err) continue } @@ -575,7 +577,9 @@ func (d *Discovery) cleanStaleExplodedBundles(ctx context.Context) { break } } - if stale { + if !stale { + continue + } explodedDir := filepath.Join(bundlesDir, manifestHash) if err = os.RemoveAll(explodedDir); err != nil { d.logger.Error("error removing exploded bundle", diff --git a/go/runtime/bundle/discovery_test.go b/go/runtime/bundle/discovery_test.go index db74f2bb965..3dd49303b44 100644 --- a/go/runtime/bundle/discovery_test.go +++ b/go/runtime/bundle/discovery_test.go @@ -74,7 +74,7 @@ func TestBundleDiscovery(t *testing.T) { // Prepare a temporary directory for storing bundles. dataDir := t.TempDir() - // Create dummy runtimeID1 + // Create dummy runtime ID. var runtimeID1 common.Namespace err := runtimeID1.UnmarshalHex("8000000000000000000000000000000000000000000000000000000000000001") require.NoError(t, err) @@ -127,7 +127,7 @@ func TestCleanStaleExplodedBundles(t *testing.T) { // Prepare a temporary directory for storing bundles. dir := t.TempDir() - // Initialize runtimes. + // Create runtime IDs. var runtimeID1 common.Namespace err := runtimeID1.UnmarshalHex("8000000000000000000000000000000000000000000000000000000000000001") require.NoError(t, err)