feat: add -l (list) and -u (unmount) flags
Update PKGBUILD version / update-pkgver (push) Successful in 5s

A second sshfsc <alias> call only printed "Already mounted"; tearing
down a mount required ls + fusermount by hand. -l lists active mounts
verified via mountinfo.Mounted, -u <Host> unmounts and removes the
empty mountpoint dir. Flags are mutually exclusive.
This commit is contained in:
2026-05-04 09:25:55 +02:00
parent 3f3c631057
commit 8edddc5a28
4 changed files with 234 additions and 8 deletions
+62
View File
@@ -4,6 +4,7 @@
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
@@ -138,3 +139,64 @@ func TestVerifyMountDirRejectsSymlink(t *testing.T) {
t.Fatalf("want symlink rejection, got %v", err)
}
}
func TestListMountsMissingBase(t *testing.T) {
runtime := t.TempDir()
t.Setenv("XDG_RUNTIME_DIR", runtime)
var buf bytes.Buffer
if err := list_mounts(&buf); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if buf.Len() != 0 {
t.Fatalf("want empty output, got %q", buf.String())
}
}
func TestListMountsFiltersUnmounted(t *testing.T) {
runtime := t.TempDir()
t.Setenv("XDG_RUNTIME_DIR", runtime)
base := filepath.Join(runtime, "sshfs")
for _, name := range []string{"stale1", "stale2"} {
if err := os.MkdirAll(filepath.Join(base, name), 0700); err != nil {
t.Fatalf("setup stale dir: %v", err)
}
}
var buf bytes.Buffer
if err := list_mounts(&buf); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if buf.Len() != 0 {
t.Fatalf("want stale dirs filtered, got %q", buf.String())
}
}
func TestUnmountRejectsBadAlias(t *testing.T) {
runtime := t.TempDir()
t.Setenv("XDG_RUNTIME_DIR", runtime)
err := unmount_sshfs("../etc")
if err == nil || !strings.Contains(err.Error(), "disallowed characters") {
t.Fatalf("want validation error, got %v", err)
}
}
func TestUnmountNotMountedMissingBase(t *testing.T) {
runtime := t.TempDir()
t.Setenv("XDG_RUNTIME_DIR", runtime)
err := unmount_sshfs("myhost")
if err == nil || !strings.Contains(err.Error(), "not mounted") {
t.Fatalf("want not-mounted error, got %v", err)
}
}
func TestUnmountNotMountedExistingDir(t *testing.T) {
runtime := t.TempDir()
t.Setenv("XDG_RUNTIME_DIR", runtime)
base := filepath.Join(runtime, "sshfs")
if err := os.MkdirAll(filepath.Join(base, "myhost"), 0700); err != nil {
t.Fatalf("setup mount dir: %v", err)
}
err := unmount_sshfs("myhost")
if err == nil || !strings.Contains(err.Error(), "not mounted") {
t.Fatalf("want not-mounted error, got %v", err)
}
}