diff --git a/cmd/osbuild-composer/composer.go b/cmd/osbuild-composer/composer.go index e9b5b7fe2..25786e794 100644 --- a/cmd/osbuild-composer/composer.go +++ b/cmd/osbuild-composer/composer.go @@ -70,10 +70,6 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string) (*Compos c.distros = distrofactory.NewDefault() - // TODO: Move this to Weldr API initialization - // Clean up the cache, removes unknown distros and files - // dnfjson.CleanupOldCacheDirs(path.Join(c.cacheDir, "rpmmd"), c.distros.List()) - c.solver = dnfjson.NewBaseSolver(path.Join(c.cacheDir, "rpmmd")) c.solver.SetDNFJSONPath(c.config.DNFJson) diff --git a/internal/dnfjson/dnfjson.go b/internal/dnfjson/dnfjson.go index fb69ecc66..8dbba415f 100644 --- a/internal/dnfjson/dnfjson.go +++ b/internal/dnfjson/dnfjson.go @@ -89,6 +89,21 @@ func (bs *BaseSolver) CleanCache() error { return bs.cache.shrink() } +// CleanupOldCacheDirs will remove cache directories for unsupported distros +// eg. Once support for a fedora release stops and it is removed, this will +// delete its directory under BaseSolver cache root. +// +// A happy side effect of this is that it will delete old cache directories +// and files from before the switch to per-distro cache directories. +// +// NOTE: This does not return any errors. This is because the most common one +// will be a nonexistant directory which will be created later, during initial +// cache creation. Any other errors like permission issues will be caught by +// later use of the cache. eg. touchRepo +func (bs *BaseSolver) CleanupOldCacheDirs(distros []string) { + CleanupOldCacheDirs(bs.cache.root, distros) +} + // Solver is configured with system information in order to resolve // dependencies for RPM packages using DNF. type Solver struct { diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 80873ea08..02a7c2caf 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -172,6 +172,9 @@ func New(repoPaths []string, stateDir string, solver *dnfjson.BaseSolver, df *di return nil, fmt.Errorf("error loading repository definitions: %v", err) } + // Clean up the cache, removes unknown distros and files + solver.CleanupOldCacheDirs(rr.ListDistros()) + hostDistro := df.GetDistro(hostDistroName) if hostDistro != nil { // get canonical distro name if the host distro is supported