mirror of
https://github.com/kopia/kopia.git
synced 2026-01-26 15:28:06 -05:00
* logging: cleaned up stderr logging - do not show module - do not show timestamps by default (enable with --console-timestamps) * logging: replaced most printStderr() with log.Info * cli: additional logging cleanup
46 lines
979 B
Go
46 lines
979 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 != "" {
|
|
log(ctx).Infof("Clearing cache directory: %v.", 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
|
|
}
|
|
|
|
log(ctx).Infof("Cache cleared.")
|
|
|
|
return nil
|
|
}
|
|
|
|
return errors.New("caching not enabled")
|
|
}
|
|
|
|
func init() {
|
|
cacheClearCommand.Action(directRepositoryAction(runCacheClearCommand))
|
|
}
|