mirror of
https://github.com/kopia/kopia.git
synced 2026-01-23 13:58:08 -05:00
38 lines
678 B
Go
38 lines
678 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.Repository) 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(repositoryAction(runCacheClearCommand))
|
|
}
|