mirror of
https://github.com/kopia/kopia.git
synced 2026-01-02 03:27:51 -05:00
- `repo.Repository` is now read-only and only has methods that can be supported over kopia server
- `repo.RepositoryWriter` has read-write methods that can be supported over kopia server
- `repo.DirectRepository` is read-only and contains all methods of `repo.Repository` plus some low-level methods for data inspection
- `repo.DirectRepositoryWriter` contains write methods for `repo.DirectRepository`
- `repo.Reader` removed and merged with `repo.Repository`
- `repo.Writer` became `repo.RepositoryWriter`
- `*repo.DirectRepository` struct became `repo.DirectRepository`
interface
Getting `{Direct}RepositoryWriter` requires using `NewWriter()` or `NewDirectWriter()` on a read-only repository and multiple simultaneous writers are supported at the same time, each writing to their own indexes and pack blobs.
`repo.Open` returns `repo.Repository` (which is also `repo.RepositoryWriter`).
* content: removed implicit flush on content manager close
* repo: added tests for WriteSession() and implicit flush behavior
* invalidate manifest manager after write session
* cli: disable maintenance in 'kopia server start'
Server will close the repository before completing.
* repo: unconditionally close RepositoryWriter in {Direct,}WriteSession
* repo: added panic in case somebody tries to create RepositoryWriter after closing repository
- used atomic to manage SharedManager.closed
* removed stale example
* linter: fixed spurious failures
Co-authored-by: Julio López <julio+gh@kasten.io>
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
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.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 errors.Wrap(err, "error removing cache directory")
|
|
}
|
|
|
|
if err := os.MkdirAll(d, 0o700); err != nil {
|
|
return errors.Wrap(err, "error creating cache directory")
|
|
}
|
|
|
|
log(ctx).Infof("Cache cleared.")
|
|
|
|
return nil
|
|
}
|
|
|
|
return errors.New("caching not enabled")
|
|
}
|
|
|
|
func init() {
|
|
cacheClearCommand.Action(directRepositoryReadAction(runCacheClearCommand))
|
|
}
|