From 9abe68848e10c65211982901d6a5ad647bef4404 Mon Sep 17 00:00:00 2001 From: Pivi Lartisant Date: Wed, 14 Aug 2024 13:19:09 +0200 Subject: [PATCH] Add Delete Fn in Cache pkg (#1365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Delete Fn in Cache pkg * fmt Co-authored-by: Nathan Seva * fmt Co-authored-by: Nathan Seva * test codecov-action@v4 * inexistence is a success Co-authored-by: Thomas Sénéchal <44696378+thomas-senechal@users.noreply.github.com> --------- Co-authored-by: Nathan Seva Co-authored-by: Thomas Sénéchal <44696378+thomas-senechal@users.noreply.github.com> --- .github/workflows/tests.yml | 2 +- pkg/cache/cache.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e21c9c7ce..6a8815c6d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,6 @@ jobs: os: ${{ matrix.os }} repo-token: ${{ secrets.GITHUB_TOKEN }} - run: task test-coverage - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 with: files: coverage.coverprofile diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index a50085fe3..9f5ceb628 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -77,3 +77,22 @@ 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 { + if os.IsNotExist(err) { + return nil + } + + return fmt.Errorf("while deleting from cache: %w", err) + } + + return nil +}