Files
kopia/cli/command_cache_clear.go
Jarek Kowalski 6cb9b8fa4f repo: refactored public API (#318)
* This is 99% mechanical:

Extracted repo.Repository interface that only exposes high-level object and manifest management methods, but not blob nor content management.

Renamed old *repo.Repository to *repo.DirectRepository

Reviewed codebase to only depend on repo.Repository as much as possible, but added way for low-level CLI commands to use DirectRepository.

* PR fixes
2020-03-26 08:04:01 -07:00

40 lines
692 B
Go

package cli
import (
"context"
"os"
"github.com/pkg/errors"
"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)
err := os.RemoveAll(d)
if err != nil {
return err
}
if err := os.MkdirAll(d, 0700); err != nil {
return err
}
printStderr("Cache cleared.\n")
return nil
}
return errors.New("caching not enabled")
}
func init() {
cacheClearCommand.Action(directRepositoryAction(runCacheClearCommand))
}