mirror of
https://github.com/octoleo/restic.git
synced 2024-12-26 04:17:29 +00:00
Merge pull request #4883 from MichaelEischer/fix-check-cache
check: fix cachedir creation when using default location
This commit is contained in:
commit
6fadc0131b
@ -7,3 +7,4 @@ The `check` command now attempts to create the cache directory before initializ
|
||||
|
||||
https://github.com/restic/restic/issues/4437
|
||||
https://github.com/restic/restic/pull/4805
|
||||
https://github.com/restic/restic/pull/4883
|
||||
|
@ -176,12 +176,14 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions, printer progress
|
||||
cachedir = cache.EnvDir()
|
||||
}
|
||||
|
||||
// use a cache in a temporary directory
|
||||
err := os.MkdirAll(cachedir, 0755)
|
||||
if err != nil {
|
||||
Warnf("unable to create cache directory %s, disabling cache: %v\n", cachedir, err)
|
||||
gopts.NoCache = true
|
||||
return cleanup
|
||||
if cachedir != "" {
|
||||
// use a cache in a temporary directory
|
||||
err := os.MkdirAll(cachedir, 0755)
|
||||
if err != nil {
|
||||
Warnf("unable to create cache directory %s, disabling cache: %v\n", cachedir, err)
|
||||
gopts.NoCache = true
|
||||
return cleanup
|
||||
}
|
||||
}
|
||||
tempdir, err := os.MkdirTemp(cachedir, "restic-check-cache-")
|
||||
if err != nil {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
@ -229,3 +230,17 @@ func TestPrepareCheckCache(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareDefaultCheckCache(t *testing.T) {
|
||||
gopts := GlobalOptions{CacheDir: ""}
|
||||
cleanup := prepareCheckCache(CheckOptions{}, &gopts, &progress.NoopPrinter{})
|
||||
_, err := os.ReadDir(gopts.CacheDir)
|
||||
rtest.OK(t, err)
|
||||
|
||||
// Call the cleanup function to remove the temporary cache directory
|
||||
cleanup()
|
||||
|
||||
// Verify that the cache directory has been removed
|
||||
_, err = os.ReadDir(gopts.CacheDir)
|
||||
rtest.Assert(t, errors.Is(err, os.ErrNotExist), "Expected cache directory to be removed, but it still exists")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user