diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-10-06 14:51:01 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-10-06 18:57:48 -0600 |
commit | 443bad3651a5f027cc97ebac4fc86cf86820d3c7 (patch) | |
tree | 6aeb51e5c5614d1dbd68b20d5ceded7802c3aba4 /cmd | |
parent | 83fa899024d54bf6027a2a382392f2492b99c915 (diff) |
ls-files: more consistent error formatting
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/btrfs-rec/inspect_lsfiles.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/cmd/btrfs-rec/inspect_lsfiles.go b/cmd/btrfs-rec/inspect_lsfiles.go index b0bb160..9267f77 100644 --- a/cmd/btrfs-rec/inspect_lsfiles.go +++ b/cmd/btrfs-rec/inspect_lsfiles.go @@ -80,13 +80,13 @@ func printSubvol(out io.Writer, prefix string, isLast bool, name string, subvol rootInode, err := subvol.GetRootInode() if err != nil { printText(out, prefix, isLast, name+"/", fmt.Sprintf("subvol_id=%v err=%v", - subvol.TreeID, err)) + subvol.TreeID, fmtErr(err))) return } dir, err := subvol.LoadDir(rootInode) if err != nil { printText(out, prefix, isLast, name+"/", fmt.Sprintf("subvol_id=%v err=%v", - subvol.TreeID, err)) + subvol.TreeID, fmtErr(err))) return } if name == "/" { @@ -102,6 +102,14 @@ func printSubvol(out io.Writer, prefix string, isLast bool, name string, subvol printDir(out, prefix, true, name, dir) } +func fmtErr(err error) string { + errStr := err.Error() + if strings.Contains(errStr, "\n") { + errStr = "\\\n" + errStr + } + return errStr +} + func fmtInode(inode btrfs.BareInode) string { var mode btrfsitem.StatMode if inode.InodeItem == nil { @@ -111,12 +119,7 @@ func fmtInode(inode btrfs.BareInode) string { } ret := fmt.Sprintf("ino=%v mode=%v", inode.Inode, mode) if len(inode.Errs) > 0 { - errStr := inode.Errs.Error() - if strings.Contains(errStr, "\n") { - ret += " err=\\\n" + errStr - } else { - ret += " err=" + errStr - } + ret += " err=" + fmtErr(inode.Errs) } return ret } @@ -149,7 +152,7 @@ func printDirEntry(out io.Writer, prefix string, isLast bool, subvol *btrfs.Subv case btrfsitem.INODE_ITEM_KEY: dir, err := subvol.LoadDir(entry.Location.ObjectID) if err != nil { - printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, err)) + printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, fmtErr(err))) return } printDir(out, prefix, isLast, name, dir) @@ -169,7 +172,7 @@ func printDirEntry(out io.Writer, prefix string, isLast bool, subvol *btrfs.Subv } file, err := subvol.LoadFile(entry.Location.ObjectID) if err != nil { - printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, err)) + printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, fmtErr(err))) return } printSymlink(out, prefix, isLast, name, file) @@ -180,7 +183,7 @@ func printDirEntry(out io.Writer, prefix string, isLast bool, subvol *btrfs.Subv } file, err := subvol.LoadFile(entry.Location.ObjectID) if err != nil { - printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, err)) + printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, fmtErr(err))) return } printFile(out, prefix, isLast, name, file) @@ -191,7 +194,7 @@ func printDirEntry(out io.Writer, prefix string, isLast bool, subvol *btrfs.Subv } file, err := subvol.LoadFile(entry.Location.ObjectID) if err != nil { - printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, err)) + printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, fmtErr(err))) return } printSocket(out, prefix, isLast, name, file) @@ -202,7 +205,7 @@ func printDirEntry(out io.Writer, prefix string, isLast bool, subvol *btrfs.Subv } file, err := subvol.LoadFile(entry.Location.ObjectID) if err != nil { - printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, err)) + printText(out, prefix, isLast, name, fmt.Sprintf("%v err=%v", entry.Type, fmtErr(err))) return } printPipe(out, prefix, isLast, name, file) |