Files
kopia/cli/command_cache_clear.go
Jarek Kowalski 9a6dea898b Linter upgrade to v1.30.0 (#526)
* fixed godot linter errors
* reformatted source with gofumpt
* disabled some linters
* fixed nolintlint warnings
* fixed gci warnings
* lint: fixed 'nestif' warnings
* lint: fixed 'exhaustive' warnings
* lint: fixed 'gocritic' warnings
* lint: fixed 'noctx' warnings
* lint: fixed 'wsl' warnings
* lint: fixed 'goerr113' warnings
* lint: fixed 'gosec' warnings
* lint: upgraded linter to 1.30.0
* lint: more 'exhaustive' warnings

Co-authored-by: Nick <nick@kasten.io>
2020-08-12 19:28:53 -07:00

46 lines
977 B
Go

package cli
import (
"context"
"os"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/retry"
"github.com/kopia/kopia/repo"
)
var cacheClearCommand = cacheCommands.Command("clear", "Clears the cache")
func runCacheClearCommand(ctx context.Context, rep *repo.DirectRepository) error {
if d := rep.Content.CachingOptions.CacheDirectory; d != "" {
printStderr("Clearing cache directory: %v.\n", d)
// close repository before removing cache
if err := rep.Close(ctx); err != nil {
return errors.Wrap(err, "unable to close repository")
}
err := retry.WithExponentialBackoffNoValue(ctx, "delete cache", func() error {
return os.RemoveAll(d)
}, retry.Always)
if err != nil {
return err
}
if err := os.MkdirAll(d, 0o700); err != nil {
return err
}
printStderr("Cache cleared.\n")
return nil
}
return errors.New("caching not enabled")
}
func init() {
cacheClearCommand.Action(directRepositoryAction(runCacheClearCommand))
}