Move cleaning up old dnfjson cache dirs from composer to Weldr API

Previously, the old dnfjson cache dirs for unsupported distributions
were deleted in the osbuild-composer binary on startup. This is no
longer possible, since the supported distros are determined by loading
available repositories. Loading repositories happens in the Weldr API
constructor. Move the cleanup code there.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-01-09 21:50:21 +01:00 committed by Achilleas Koutsou
parent 625b1578fa
commit fb1b27c0ef
3 changed files with 18 additions and 4 deletions

View file

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

View file

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

View file

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