From cfcc6d385a92192dc8fbfa8ab10d173b292e41b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 9 Jan 2024 21:50:21 +0100 Subject: [PATCH] Move cleaning up old dnfjson cache dirs from composer to Weldr API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkg/dnfjson/dnfjson.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/dnfjson/dnfjson.go b/pkg/dnfjson/dnfjson.go index 2587c2e2f5..71bac57dfb 100644 --- a/pkg/dnfjson/dnfjson.go +++ b/pkg/dnfjson/dnfjson.go @@ -105,6 +105,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 {