From 058e3d6832651380882bcad89352a1cc830c50a8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 18 Dec 2024 11:03:36 +0100 Subject: [PATCH] manifestgen: use temporary cache dir if no cacheDir is given This commit creates a temporary directory for the defaultDepvolver() if no cacheDir is given. This ensures that we do not clutter the current working directory with `platform:foo` cache directories that `solver.Depvolve()` creates. Note that this is only tested indirectly via the integration test in `test_container.py:test_container_builds_image()` that checks that the output directory is clean. --- internal/manifestgen/manifestgen.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/manifestgen/manifestgen.go b/internal/manifestgen/manifestgen.go index 1c912eb..560c3a7 100644 --- a/internal/manifestgen/manifestgen.go +++ b/internal/manifestgen/manifestgen.go @@ -22,6 +22,15 @@ import ( // into a common helper in "images" or images should do this on its // own func defaultDepsolver(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d distro.Distro, arch string) (map[string][]rpmmd.PackageSpec, map[string][]rpmmd.RepoConfig, error) { + if cacheDir == "" { + var err error + cacheDir, err = os.MkdirTemp("", "manifestgen") + if err != nil { + return nil, nil, fmt.Errorf("cannot create temporary directory: %w", err) + } + defer os.RemoveAll(cacheDir) + } + solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch, d.Name(), cacheDir) depsolvedSets := make(map[string][]rpmmd.PackageSpec) repoSets := make(map[string][]rpmmd.RepoConfig)