mirror of
https://github.com/kopia/kopia.git
synced 2026-01-26 15:28:06 -05:00
Also introduced strongly typed content.ID and manifest.ID (instead of string) This aligns identifiers across all layers of repository: blob.ID content.ID object.ID manifest.ID
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
var (
|
|
blockIndexListCommand = indexCommands.Command("list", "List content indexes").Alias("ls").Default()
|
|
blockIndexListSummary = blockIndexListCommand.Flag("summary", "Display index blob summary").Bool()
|
|
blockIndexListSort = blockIndexListCommand.Flag("sort", "Index blob sort order").Default("time").Enum("time", "size", "name")
|
|
)
|
|
|
|
func runListBlockIndexesAction(ctx context.Context, rep *repo.Repository) error {
|
|
blks, err := rep.Content.IndexBlobs(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch *blockIndexListSort {
|
|
case "time":
|
|
sort.Slice(blks, func(i, j int) bool {
|
|
return blks[i].Timestamp.Before(blks[j].Timestamp)
|
|
})
|
|
case "size":
|
|
sort.Slice(blks, func(i, j int) bool {
|
|
return blks[i].Length < blks[j].Length
|
|
})
|
|
case "name":
|
|
sort.Slice(blks, func(i, j int) bool {
|
|
return blks[i].BlobID < blks[j].BlobID
|
|
})
|
|
}
|
|
|
|
for _, b := range blks {
|
|
fmt.Printf("%-70v %10v %v\n", b.BlobID, b.Length, formatTimestampPrecise(b.Timestamp))
|
|
}
|
|
|
|
if *blockIndexListSummary {
|
|
fmt.Printf("total %v blocks\n", len(blks))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
blockIndexListCommand.Action(repositoryAction(runListBlockIndexesAction))
|
|
}
|