From f1f69bc6482f51ed6370aa0426410e1bbce2db51 Mon Sep 17 00:00:00 2001 From: Garry McNulty Date: Fri, 20 Jul 2018 20:51:20 +0100 Subject: [PATCH 1/2] check: Use --cache-dir argument Closes #1880 --- changelog/unreleased/issue-1880 | 7 +++++++ cmd/restic/cmd_check.go | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 changelog/unreleased/issue-1880 diff --git a/changelog/unreleased/issue-1880 b/changelog/unreleased/issue-1880 new file mode 100644 index 000000000..95180ae58 --- /dev/null +++ b/changelog/unreleased/issue-1880 @@ -0,0 +1,7 @@ +Bugfix: Use `--cache-dir` argument for `check` command + +`check` command now uses a specific cache directory if set using the `--cache-dir` argument. + +The `--cache-dir` argument was not used by the `check` command, instead a cache directory was created in the temporary directory. + +https://github.com/restic/restic/issues/1880 diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 33b5f3725..ac7be5d49 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -122,6 +122,7 @@ func newReadProgress(gopts GlobalOptions, todo restic.Stat) *restic.Progress { // prepareCheckCache configures a special cache directory for check. // // * if --with-cache is specified, the default cache is used +// * if the user provides --cache-dir, the specified directory is used // * if the user explicitly requested --no-cache, we don't use any cache // * by default, we use a cache in a temporary directory that is deleted after the check func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func()) { @@ -131,6 +132,11 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func()) return cleanup } + if gopts.CacheDir != "" { + // use the specified cache directory, no setup needed + return cleanup + } + if gopts.NoCache { // don't use any cache, no setup needed return cleanup From 7603ab7ac1ce7fea392f88a03a6ba4fd5b1b8198 Mon Sep 17 00:00:00 2001 From: Garry McNulty Date: Sun, 22 Jul 2018 18:24:11 +0100 Subject: [PATCH 2/2] check: Update --cache-dir argument handling based on code review comments The temporary cache directory is created in the specified directory, or if not specified in the default temporary directory. --- changelog/unreleased/issue-1880 | 9 +++++++-- cmd/restic/cmd_check.go | 11 ++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/changelog/unreleased/issue-1880 b/changelog/unreleased/issue-1880 index 95180ae58..cd144e40a 100644 --- a/changelog/unreleased/issue-1880 +++ b/changelog/unreleased/issue-1880 @@ -1,7 +1,12 @@ Bugfix: Use `--cache-dir` argument for `check` command -`check` command now uses a specific cache directory if set using the `--cache-dir` argument. +`check` command now uses a temporary sub-directory of the specified directory +if set using the `--cache-dir` argument. If not set, the cache directory is +created in the default temporary directory as before. +In either case a temporary cache is used to ensure the actual repository is +checked (rather than a local copy). -The `--cache-dir` argument was not used by the `check` command, instead a cache directory was created in the temporary directory. +The `--cache-dir` argument was not used by the `check` command, instead a +cache directory was created in the temporary directory. https://github.com/restic/restic/issues/1880 diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index ac7be5d49..bee7eae54 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -122,8 +122,8 @@ func newReadProgress(gopts GlobalOptions, todo restic.Stat) *restic.Progress { // prepareCheckCache configures a special cache directory for check. // // * if --with-cache is specified, the default cache is used -// * if the user provides --cache-dir, the specified directory is used // * if the user explicitly requested --no-cache, we don't use any cache +// * if the user provides --cache-dir, we use a cache in a temporary sub-directory of the specified directory and the sub-directory is deleted after the check // * by default, we use a cache in a temporary directory that is deleted after the check func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func()) { cleanup = func() {} @@ -132,18 +132,15 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func()) return cleanup } - if gopts.CacheDir != "" { - // use the specified cache directory, no setup needed - return cleanup - } - if gopts.NoCache { // don't use any cache, no setup needed return cleanup } + cachedir := gopts.CacheDir + // use a cache in a temporary directory - tempdir, err := ioutil.TempDir("", "restic-check-cache-") + tempdir, err := ioutil.TempDir(cachedir, "restic-check-cache-") if err != nil { // if an error occurs, don't use any cache Warnf("unable to create temporary directory for cache during check, disabling cache: %v\n", err)