From 3399f982ae4eed22617585a7cf2c647a71df7c83 Mon Sep 17 00:00:00 2001 From: Phoebe Lartisant Date: Thu, 8 Aug 2024 16:29:08 +0200 Subject: [PATCH] Add Delete Fn in Cache pkg --- pkg/cache/cache.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index a50085fe3..32327c0d7 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -77,3 +77,19 @@ func (c *Cache) Save(fileName string, content []byte) error { return nil } + +// Delete removes a file from the cache. +func (c *Cache) Delete(fileName string) error { + + fullPath, err := fullPath(fileName, c.ConfigDir) + if err != nil { + return fmt.Errorf("while reading cached file %s: %w", fileName, err) + } + + err = os.Remove(fullPath) + if err != nil { + return fmt.Errorf("while deleting from cache: %v", err) + } + + return nil +}