From a6a37b709a7a52ce08c4998e31edaaeacdbe2fba Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Sun, 8 Oct 2017 20:49:25 -0700 Subject: [PATCH] added pack info output to 'block list' --- cli/command_block_list.go | 24 ++++++++++++++++++++++-- repo/block_manager.go | 20 ++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/cli/command_block_list.go b/cli/command_block_list.go index 9a90161b2..acbcdaaaa 100644 --- a/cli/command_block_list.go +++ b/cli/command_block_list.go @@ -4,6 +4,8 @@ "fmt" "sort" + "github.com/kopia/kopia/repo" + kingpin "gopkg.in/alecthomas/kingpin.v2" ) @@ -12,7 +14,7 @@ blockListKind = blockListCommand.Flag("kind", "Block kind").Default("all").Enum("all", "physical", "packed", "nonpacked", "packs") blockListLong = blockListCommand.Flag("long", "Long output").Short('l').Bool() blockListPrefix = blockListCommand.Flag("prefix", "Prefix").String() - blockListSort = blockListCommand.Flag("sort", "Sort order").Default("name").Enum("name", "size", "time", "none") + blockListSort = blockListCommand.Flag("sort", "Sort order").Default("name").Enum("name", "size", "time", "none", "pack") blockListReverse = blockListCommand.Flag("reverse", "Reverse sort").Short('r').Bool() ) @@ -34,11 +36,21 @@ func runListBlocksAction(context *kingpin.ParseContext) error { sort.Slice(blocks, func(i, j int) bool { return maybeReverse(blocks[i].Length < blocks[j].Length) }) case "time": sort.Slice(blocks, func(i, j int) bool { return maybeReverse(blocks[i].Timestamp.Before(blocks[j].Timestamp)) }) + case "pack": + sort.Slice(blocks, func(i, j int) bool { return maybeReverse(comparePacks(blocks[i], blocks[j])) }) } for _, b := range blocks { if *blockListLong { - fmt.Printf("%-34v %10v %v %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormat), b.PackGroup) + grp := b.PackGroup + if grp == "" { + grp = "default" + } + if b.PackBlockID != "" { + fmt.Printf("%-34v %10v %v %v in %v offset %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormat), grp, b.PackBlockID, b.PackOffset) + } else { + fmt.Printf("%-34v %10v %v %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormat), grp) + } } else { fmt.Printf("%v\n", b.BlockID) } @@ -47,6 +59,14 @@ func runListBlocksAction(context *kingpin.ParseContext) error { return nil } +func comparePacks(a, b repo.BlockInfo) bool { + if a, b := a.PackBlockID, b.PackBlockID; a != b { + return a < b + } + + return a.PackOffset < b.PackOffset +} + func init() { blockListCommand.Action(runListBlocksAction) } diff --git a/repo/block_manager.go b/repo/block_manager.go index 8b2c339f5..3d6071459 100644 --- a/repo/block_manager.go +++ b/repo/block_manager.go @@ -34,10 +34,12 @@ type blockLocation struct { // BlockInfo is an information about a single block managed by BlockManager. type BlockInfo struct { - BlockID string - Length int64 - Timestamp time.Time - PackGroup string + BlockID string + Length int64 + Timestamp time.Time + PackGroup string + PackBlockID string + PackOffset int64 } // BlockManager manages storage blocks at a low level with encryption, deduplication and packaging. @@ -504,10 +506,12 @@ func (bm *BlockManager) ListBlocks(prefix string, kind string) []BlockInfo { } bm := BlockInfo{ - BlockID: b, - Length: int64(ndx.Items[b].size), - Timestamp: ndx.CreateTime, - PackGroup: ndx.PackGroup, + BlockID: b, + Length: int64(ndx.Items[b].size), + Timestamp: ndx.CreateTime, + PackGroup: ndx.PackGroup, + PackBlockID: ndx.PackBlockID, + PackOffset: int64(ndx.Items[b].offset), } if !blockMatches(bm, ndx) {