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/main.go | |
parent | 6b8c24fb78f0face6532c1170ff0dca46dd56223 (diff) |
cmd/btrfs-rec: ls-trees: Use runWithReadableFS
Diffstat (limited to 'cmd/btrfs-rec/main.go')
-rw-r--r-- | cmd/btrfs-rec/main.go | 22 |
1 files changed, 22 insertions, 0 deletions
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) + }) +} |