Files
kopia/cli/command_content_show.go
Jarek Kowalski fa7976599c repo: refactored repository interfaces (#780)
- `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>
2021-01-20 11:41:47 -08:00

42 lines
993 B
Go

package cli
import (
"bytes"
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/content"
)
var (
contentShowCommand = contentCommands.Command("show", "Show contents by ID.").Alias("cat")
contentShowIDs = contentShowCommand.Arg("id", "IDs of contents to show").Required().Strings()
)
func runContentShowCommand(ctx context.Context, rep repo.DirectRepository) error {
for _, contentID := range toContentIDs(*contentShowIDs) {
if err := contentShow(ctx, rep, contentID); err != nil {
return err
}
}
return nil
}
func contentShow(ctx context.Context, r repo.DirectRepository, contentID content.ID) error {
data, err := r.ContentReader().GetContent(ctx, contentID)
if err != nil {
return errors.Wrapf(err, "error getting content %v", contentID)
}
return showContent(bytes.NewReader(data))
}
func init() {
setupShowCommand(contentShowCommand)
contentShowCommand.Action(directRepositoryReadAction(runContentShowCommand))
}