From ffca8ae2b240012f8285e24fd4ca152be5d86906 Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Mon, 26 Feb 2024 14:30:38 -0600 Subject: [PATCH] Immediately access shares when adding them --- ipn/ipnlocal/tailfs.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ipn/ipnlocal/tailfs.go b/ipn/ipnlocal/tailfs.go index d06599661..fc5e5e16f 100644 --- a/ipn/ipnlocal/tailfs.go +++ b/ipn/ipnlocal/tailfs.go @@ -80,6 +80,25 @@ func (b *LocalBackend) TailFSAddShare(share *tailfs.Share) error { return err } + // Make sure share is actually a directory. + dir, err := os.Open(share.Name) + if err != nil { + return err + } + fi, err := dir.Stat() + if err != nil { + return err + } + if !fi.IsDir() { + return fmt.Errorf("%q is not a directory", share.Name) + } + // Immediately access each share to prompt the user for file access on + // platforms that require it (e.g. MacOS sandboxed). + _, err = dir.ReadDir(1) + if err != nil { + return err + } + b.mu.Lock() shares, err := b.tailfsAddShareLocked(share) b.mu.Unlock()