diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/btrfs-rec/inspect_rebuildmappings.go | 1 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_rebuildnodes.go | 24 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_scandevices.go | 7 |
3 files changed, 27 insertions, 5 deletions
diff --git a/cmd/btrfs-rec/inspect_rebuildmappings.go b/cmd/btrfs-rec/inspect_rebuildmappings.go index ce90139..54535ec 100644 --- a/cmd/btrfs-rec/inspect_rebuildmappings.go +++ b/cmd/btrfs-rec/inspect_rebuildmappings.go @@ -51,6 +51,7 @@ func init() { if err := writeMappingsJSON(os.Stdout, fs); err != nil { return err } + dlog.Info(ctx, "... done writing") return nil }, diff --git a/cmd/btrfs-rec/inspect_rebuildnodes.go b/cmd/btrfs-rec/inspect_rebuildnodes.go index df9a977..36a9207 100644 --- a/cmd/btrfs-rec/inspect_rebuildnodes.go +++ b/cmd/btrfs-rec/inspect_rebuildnodes.go @@ -5,14 +5,17 @@ package main import ( - "encoding/json" + "bufio" + "io" "os" + "git.lukeshu.com/go/lowmemjson" "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/btrfs/btrfsvol" "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildnodes" ) @@ -38,9 +41,7 @@ func init() { } dlog.Info(ctx, "Writing re-built nodes to stdout...") - encoder := json.NewEncoder(os.Stdout) - encoder.SetIndent("", " ") - if err := encoder.Encode(rebuiltNodes); err != nil { + if err := writeNodesJSON(os.Stdout, rebuiltNodes); err != nil { return err } dlog.Info(ctx, "... done writing") @@ -49,3 +50,18 @@ func init() { }, }) } + +func writeNodesJSON(w io.Writer, rebuiltNodes map[btrfsvol.LogicalAddr]*rebuildnodes.RebuiltNode) (err error) { + buffer := bufio.NewWriter(w) + defer func() { + if _err := buffer.Flush(); err == nil && _err != nil { + err = _err + } + }() + return lowmemjson.Encode(&lowmemjson.ReEncoder{ + Out: buffer, + + Indent: "\t", + ForceTrailingNewlines: true, + }, rebuiltNodes) +} diff --git a/cmd/btrfs-rec/inspect_scandevices.go b/cmd/btrfs-rec/inspect_scandevices.go index 37bafe4..5c8b2b0 100644 --- a/cmd/btrfs-rec/inspect_scandevices.go +++ b/cmd/btrfs-rec/inspect_scandevices.go @@ -33,7 +33,12 @@ func init() { } dlog.Info(ctx, "Writing scan results to stdout...") - return writeScanResults(os.Stdout, results) + if err := writeScanResults(os.Stdout, results); err != nil { + return err + } + dlog.Info(ctx, "... done writing") + + return nil }, }) } |