From 00d35018d1ffbd1cf7f7ea8cb5ea2e20bb4b3ca7 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 28 May 2024 12:01:49 +0200 Subject: [PATCH] blobinfocache: add function to delete the cache directory Needed for: https://github.com/containers/podman/issues/22825 Signed-off-by: Giuseppe Scrivano --- pkg/blobinfocache/default.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/blobinfocache/default.go b/pkg/blobinfocache/default.go index 037572b0e..b413ec513 100644 --- a/pkg/blobinfocache/default.go +++ b/pkg/blobinfocache/default.go @@ -74,3 +74,15 @@ func DefaultCache(sys *types.SystemContext) types.BlobInfoCache { logrus.Debugf("Using SQLite blob info cache at %s", path) return cache } + +// CleanupDefaultCache removes the blob info cache directory. +// It deletes the cache directory but it does not affect any file or memory buffer currently +// in use. +func CleanupDefaultCache(sys *types.SystemContext) error { + dir, err := blobInfoCacheDir(sys, rootless.GetRootlessEUID()) + if err != nil { + // Mirror the DefaultCache behavior that does not fail in this case + return nil + } + return os.RemoveAll(dir) +}