Files
kopia/cli/command_index_list.go
Jarek Kowalski e03971fc59 Upgraded linter to v1.33.0 (#734)
* linter: upgraded to 1.33, disabled some linters

* lint: fixed 'errorlint' errors

This ensures that all error comparisons use errors.Is() or errors.As().
We will be wrapping more errors going forward so it's important that
error checks are not strict everywhere.

Verified that there are no exceptions for errorlint linter which
guarantees that.

* lint: fixed or suppressed wrapcheck errors

* lint: nolintlint and misc cleanups

Co-authored-by: Julio López <julio+gh@kasten.io>
2020-12-21 22:39:22 -08:00

55 lines
1.5 KiB
Go

package cli
import (
"context"
"fmt"
"sort"
"github.com/pkg/errors"
"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()
blockIndexListIncludeSuperseded = blockIndexListCommand.Flag("superseded", "Include inactive index files superseded by compaction").Bool()
blockIndexListSort = blockIndexListCommand.Flag("sort", "Index blob sort order").Default("time").Enum("time", "size", "name")
)
func runListBlockIndexesAction(ctx context.Context, rep *repo.DirectRepository) error {
blks, err := rep.Content.IndexBlobs(ctx, *blockIndexListIncludeSuperseded)
if err != nil {
return errors.Wrap(err, "error listing index blobs")
}
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("%-40v %10v %v %v\n", b.BlobID, b.Length, formatTimestampPrecise(b.Timestamp), b.Superseded)
}
if *blockIndexListSummary {
fmt.Printf("total %v indexes\n", len(blks))
}
return nil
}
func init() {
blockIndexListCommand.Action(directRepositoryAction(runListBlockIndexesAction))
}