refactor: delegate -l output to findmnt
Update PKGBUILD version / update-pkgver (push) Successful in 2s
Update PKGBUILD version / update-pkgver (push) Successful in 2s
The custom one-alias-per-line output was useless — no mountpoint, no source, no options. Reinventing a table format when findmnt from util-linux already produces a familiar fuse.sshfs view was the wrong call. -l now shells out to findmnt -t fuse.sshfs.
This commit is contained in:
@@ -281,26 +281,22 @@ func is_mounted_at(path string) (bool, error) {
|
||||
}
|
||||
|
||||
func list_mounts(out io.Writer) error {
|
||||
base, err := mount_base(false)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
cmd := exec.Command("findmnt", "-t", "fuse.sshfs")
|
||||
cmd.Stdout = out
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
mounts, err := mountinfo.GetMounts(mountinfo.PrefixFilter(base))
|
||||
if err != nil {
|
||||
return fmt.Errorf("read mountinfo: %w", err)
|
||||
// findmnt exits 1 when no matching mount exists — not an error here.
|
||||
var ee *exec.ExitError
|
||||
if errors.As(err, &ee) && ee.ExitCode() == 1 {
|
||||
return nil
|
||||
}
|
||||
prefix := base + string(os.PathSeparator)
|
||||
for _, m := range mounts {
|
||||
rel := strings.TrimPrefix(m.Mountpoint, prefix)
|
||||
if rel == "" || strings.Contains(rel, string(os.PathSeparator)) {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintln(out, rel)
|
||||
if errors.Is(err, exec.ErrNotFound) {
|
||||
return fmt.Errorf("findmnt not found (install util-linux)")
|
||||
}
|
||||
return nil
|
||||
return fmt.Errorf("findmnt: %w", err)
|
||||
}
|
||||
|
||||
func run_fusermount(flag, mount string) error {
|
||||
|
||||
Reference in New Issue
Block a user