diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-10 19:31:50 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-04 14:08:38 -0600 |
commit | bc94e6dbf6e9212820615a3d3f3e4542693351a6 (patch) | |
tree | 81270d70f8c8b2f3353bf3a12b06b913d989522a /cmd/btrfs-rec | |
parent | 6b8c24fb78f0face6532c1170ff0dca46dd56223 (diff) |
cmd/btrfs-rec: ls-trees: Use runWithReadableFS
Diffstat (limited to 'cmd/btrfs-rec')
-rw-r--r-- | cmd/btrfs-rec/inspect_lstrees.go | 13 | ||||
-rw-r--r-- | cmd/btrfs-rec/main.go | 22 |
2 files changed, 23 insertions, 12 deletions
diff --git a/cmd/btrfs-rec/inspect_lstrees.go b/cmd/btrfs-rec/inspect_lstrees.go index 24622b4..cb7bef8 100644 --- a/cmd/btrfs-rec/inspect_lstrees.go +++ b/cmd/btrfs-rec/inspect_lstrees.go @@ -33,20 +33,9 @@ func init() { "If no --node-list is given, then a slow sector-by-sector scan " + "will be used to find all lost+found nodes.", Args: cliutil.WrapPositionalArgs(cobra.NoArgs), - RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) error { + RunE: runWithReadableFSAndNodeList(&nodeListFilename, func(fs btrfs.ReadableFS, nodeList []btrfsvol.LogicalAddr, cmd *cobra.Command, _ []string) error { ctx := cmd.Context() - var nodeList []btrfsvol.LogicalAddr - var err error - if nodeListFilename != "" { - nodeList, err = readJSONFile[[]btrfsvol.LogicalAddr](ctx, nodeListFilename) - } else { - nodeList, err = btrfsutil.ListNodes(ctx, fs) - } - if err != nil { - return err - } - var treeErrCnt int var treeItemCnt map[btrfsitem.Type]int flush := func() { diff --git a/cmd/btrfs-rec/main.go b/cmd/btrfs-rec/main.go index 49a9649..8d3193a 100644 --- a/cmd/btrfs-rec/main.go +++ b/cmd/btrfs-rec/main.go @@ -192,3 +192,25 @@ func runWithReadableFS(runE func(btrfs.ReadableFS, *cobra.Command, []string) err return runE(rfs, cmd, args) }) } + +func runWithReadableFSAndNodeList(nodeListFilename *string, runE func(btrfs.ReadableFS, []btrfsvol.LogicalAddr, *cobra.Command, []string) error) func(*cobra.Command, []string) error { + return runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, args []string) error { + var nodeList []btrfsvol.LogicalAddr + var err error + if *nodeListFilename != "" { + nodeList, err = readJSONFile[[]btrfsvol.LogicalAddr](cmd.Context(), *nodeListFilename) + } else { + nodeList, err = btrfsutil.ListNodes(cmd.Context(), fs) + } + if err != nil { + return err + } + + var rfs btrfs.ReadableFS = fs + if globalFlags.rebuild { + rfs = btrfsutil.NewOldRebuiltForrest(fs) + } + + return runE(rfs, nodeList, cmd, args) + }) +} |