mirror of
https://github.com/octoleo/restic.git
synced 2024-12-27 04:32:40 +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/issues/4437
|
||||||
https://github.com/restic/restic/pull/4805
|
https://github.com/restic/restic/pull/4805
|
||||||
|
https://github.com/restic/restic/pull/4883
|
||||||
|
@ -176,6 +176,7 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions, printer progress
|
|||||||
cachedir = cache.EnvDir()
|
cachedir = cache.EnvDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cachedir != "" {
|
||||||
// use a cache in a temporary directory
|
// use a cache in a temporary directory
|
||||||
err := os.MkdirAll(cachedir, 0755)
|
err := os.MkdirAll(cachedir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -183,6 +184,7 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions, printer progress
|
|||||||
gopts.NoCache = true
|
gopts.NoCache = true
|
||||||
return cleanup
|
return cleanup
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tempdir, err := os.MkdirTemp(cachedir, "restic-check-cache-")
|
tempdir, err := os.MkdirTemp(cachedir, "restic-check-cache-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if an error occurs, don't use any cache
|
// if an error occurs, don't use any cache
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
"github.com/restic/restic/internal/ui/progress"
|
"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