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.
This commit is contained in:
Michael Vogt 2024-12-18 11:03:36 +01:00
parent cc4a730381
commit 058e3d6832

View file

@ -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)