From 61708772a2df82d723fa0843bce061e0b5733071 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 14 Jun 2026 11:17:29 +0200 Subject: [PATCH] mount: use existing HasPathPrefix helper replaces the custom isInside helper to check path nesting --- cmd/restic/cmd_mount.go | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 010d1a7e0..2c9decc7c 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -19,6 +19,7 @@ import ( "github.com/restic/restic/internal/data" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" @@ -26,7 +27,7 @@ import ( "github.com/restic/restic/internal/fuse" systemFuse "github.com/anacrolix/fuse" - "github.com/anacrolix/fuse/fs" + fusefs "github.com/anacrolix/fuse/fs" ) func registerMountCommand(cmdRoot *cobra.Command, globalOptions *global.Options) { @@ -197,7 +198,7 @@ func runMount(ctx context.Context, opts MountOptions, gopts global.Options, args go func() { defer close(done) - err = fs.Serve(c, root) + err = fusefs.Serve(c, root) }() printer.S("Now serving the repository at %s", mountpoint) @@ -271,9 +272,9 @@ func checkMountpointOverlap(repoPath, mountpoint string) error { switch { case rp == mp: return errors.Fatal(fmt.Sprintf("mountpoint %s is the local repository directory%s", mp, tail)) - case isInside(rp, mp): + case fs.HasPathPrefix(rp, mp): return errors.Fatal(fmt.Sprintf("mountpoint %s is inside the local repository directory %s%s", mp, rp, tail)) - case isInside(mp, rp): + case fs.HasPathPrefix(mp, rp): return errors.Fatal(fmt.Sprintf("local repository directory %s is inside the mountpoint %s%s", rp, mp, tail)) } return nil @@ -294,17 +295,3 @@ func resolvePath(p string) (string, error) { } return resolved, nil } - -// isInside reports whether child is strictly nested inside parent. Both paths -// must already be cleaned and absolute. Equal paths return false; the caller -// handles equality separately so it can produce a distinct error message. -func isInside(parent, child string) bool { - rel, err := filepath.Rel(parent, child) - if err != nil { - return false - } - if rel == "." || rel == ".." { - return false - } - return !strings.HasPrefix(rel, ".."+string(filepath.Separator)) -}