Skip to content

Commit

Permalink
Fixup: Code Quality
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Nose <[email protected]>
  • Loading branch information
martintomazic and peternose committed Jan 14, 2025
1 parent 8bfe9f6 commit 622d0bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
34 changes: 18 additions & 16 deletions go/runtime/bundle/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -83,7 +83,7 @@ func NewDiscovery(dataDir string, registry Registry, runtimeIDsCfg []common.Name
client: &client,
maxBundleSizeBytes: bundleSize,
registry: registry,
runtimeIDsCfg: runtimeIDsCfg,
runtimeIDsCfg: runtimeIDs,
logger: *logger,
}
}
Expand Down Expand Up @@ -527,17 +527,19 @@ 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)
if err != nil {
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 {
Expand All @@ -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
}
Expand All @@ -575,20 +577,20 @@ func (d *Discovery) cleanStaleExplodedBundles(ctx context.Context) {
break
}
}
if stale {
explodedDir := filepath.Join(bundlesDir, manifestHash)
if err = os.RemoveAll(explodedDir); err != nil {
d.logger.Error("error removing exploded bundle",
"manifestHash", manifestHash,
"err", err)
continue
}

if !stale {
continue
}
explodedDir := filepath.Join(bundlesDir, manifestHash)
if err = os.RemoveAll(explodedDir); err != nil {
d.logger.Error("error removing exploded bundle",
"manifestHash", manifestHash,
"err", err)
continue
}

}
}
}

cleanDir(d.bundleDir)
cleanDir(filepath.Join(d.bundleDir, DetachedSubdir))
}
Expand Down
4 changes: 2 additions & 2 deletions go/runtime/bundle/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 622d0bd

Please sign in to comment.