summaryrefslogtreecommitdiff
path: root/cmd/btrfs-rec/inspect_dumpsums.go
blob: 28ae7ef84b77099a83a3548f9b471fd9ef9b22b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2022  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package main

import (
	"os"

	"github.com/datawire/dlib/dlog"
	"github.com/datawire/ocibuild/pkg/cliutil"
	"github.com/spf13/cobra"

	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
	"git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildmappings"
)

func init() {
	inspectors = append(inspectors, subcommand{
		Command: cobra.Command{
			Use:   "dump-sums",
			Short: "Dump a buncha checksums as JSON",
			Args:  cliutil.WrapPositionalArgs(cobra.NoArgs),
		},
		RunE: func(fs *btrfs.FS, cmd *cobra.Command, _ []string) error {
			ctx := cmd.Context()
			sums, err := rebuildmappings.SumEverything(ctx, fs)
			if err != nil {
				return err
			}
			dlog.Info(ctx, "Writing sums as gob to stdout...")
			return rebuildmappings.WriteAllSums(os.Stdout, sums)
		},
	})
}