mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -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>
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/internal/stats"
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/repo/content"
|
|
)
|
|
|
|
var (
|
|
contentListCommand = contentCommands.Command("list", "List contents").Alias("ls")
|
|
contentListLong = contentListCommand.Flag("long", "Long output").Short('l').Bool()
|
|
contentListIncludeDeleted = contentListCommand.Flag("deleted", "Include deleted content").Bool()
|
|
contentListDeletedOnly = contentListCommand.Flag("deleted-only", "Only show deleted content").Bool()
|
|
contentListSummary = contentListCommand.Flag("summary", "Summarize the list").Short('s').Bool()
|
|
contentListHuman = contentListCommand.Flag("human", "Human-readable output").Short('h').Bool()
|
|
)
|
|
|
|
func runContentListCommand(ctx context.Context, rep repo.DirectRepository) error {
|
|
var totalSize stats.CountSum
|
|
|
|
err := rep.ContentReader().IterateContents(
|
|
ctx,
|
|
content.IterateOptions{
|
|
Range: contentIDRange(),
|
|
IncludeDeleted: *contentListIncludeDeleted || *contentListDeletedOnly,
|
|
},
|
|
func(b content.Info) error {
|
|
if *contentListDeletedOnly && !b.Deleted {
|
|
return nil
|
|
}
|
|
|
|
totalSize.Add(int64(b.Length))
|
|
|
|
if *contentListLong {
|
|
optionalDeleted := ""
|
|
if b.Deleted {
|
|
optionalDeleted = " (deleted)"
|
|
}
|
|
fmt.Printf("%v %v %v %v+%v%v\n",
|
|
b.ID,
|
|
formatTimestamp(b.Timestamp()),
|
|
b.PackBlobID,
|
|
b.PackOffset,
|
|
maybeHumanReadableBytes(*contentListHuman, int64(b.Length)),
|
|
optionalDeleted)
|
|
} else {
|
|
fmt.Printf("%v\n", b.ID)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return errors.Wrap(err, "error iterating")
|
|
}
|
|
|
|
if *contentListSummary {
|
|
count, sz := totalSize.Approximate()
|
|
fmt.Printf("Total: %v contents, %v total size\n",
|
|
maybeHumanReadableCount(*contentListHuman, int64(count)),
|
|
maybeHumanReadableBytes(*contentListHuman, sz))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
contentListCommand.Action(directRepositoryReadAction(runContentListCommand))
|
|
setupContentIDRangeFlags(contentListCommand)
|
|
}
|