mirror of
https://github.com/kopia/kopia.git
synced 2026-03-12 19:26:25 -04: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>
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
var (
|
|
manifestListCommand = manifestCommands.Command("list", "List manifest items").Alias("ls").Default()
|
|
manifestListFilter = manifestListCommand.Flag("filter", "List of key:value pairs").Strings()
|
|
manifestListSort = manifestListCommand.Flag("sort", "List of keys to sort by").Strings()
|
|
)
|
|
|
|
func init() {
|
|
manifestListCommand.Action(repositoryReaderAction(listManifestItems))
|
|
}
|
|
|
|
func listManifestItems(ctx context.Context, rep repo.Repository) error {
|
|
filter := map[string]string{}
|
|
|
|
for _, kv := range *manifestListFilter {
|
|
p := strings.Index(kv, ":")
|
|
if p <= 0 {
|
|
return errors.Errorf("invalid list filter %q, missing ':'", kv)
|
|
}
|
|
|
|
filter[kv[0:p]] = kv[p+1:]
|
|
}
|
|
|
|
items, err := rep.FindManifests(ctx, filter)
|
|
if err != nil {
|
|
return errors.Wrap(err, "unable to find manifests")
|
|
}
|
|
|
|
sort.Slice(items, func(i, j int) bool {
|
|
for _, key := range *manifestListSort {
|
|
if v1, v2 := items[i].Labels[key], items[j].Labels[key]; v1 != v2 {
|
|
return v1 < v2
|
|
}
|
|
}
|
|
|
|
return items[i].ModTime.Before(items[j].ModTime)
|
|
})
|
|
|
|
for _, it := range items {
|
|
t := it.Labels["type"]
|
|
fmt.Printf("%v %10v %v type:%v %v\n", it.ID, it.Length, formatTimestamp(it.ModTime.Local()), t, sortedMapValues(it.Labels))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func sortedMapValues(m map[string]string) string {
|
|
var result []string
|
|
|
|
for k, v := range m {
|
|
if k == "type" {
|
|
continue
|
|
}
|
|
|
|
result = append(result, fmt.Sprintf("%v:%v", k, v))
|
|
}
|
|
|
|
sort.Strings(result)
|
|
|
|
return strings.Join(result, " ")
|
|
}
|