From 4b7016b89f07b2514523e7ad9e0662e4fea568a2 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Fri, 28 Nov 2025 14:22:01 +0000 Subject: [PATCH] snapshot: prevent duplicate calls to mount returning different values In addition to being wasteful, without this, concurrent calls to `Mount` would have lost the previous `target` and so would never have been removed. Signed-off-by: Justin Chadwell --- snapshot/localmounter_darwin.go | 4 ++++ snapshot/localmounter_freebsd.go | 4 ++++ snapshot/localmounter_linux.go | 4 ++++ snapshot/localmounter_windows.go | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/snapshot/localmounter_darwin.go b/snapshot/localmounter_darwin.go index 9acf3a950..570bc930a 100644 --- a/snapshot/localmounter_darwin.go +++ b/snapshot/localmounter_darwin.go @@ -13,6 +13,10 @@ func (lm *localMounter) Mount() (string, error) { lm.mu.Lock() defer lm.mu.Unlock() + if lm.target != "" { + return lm.target, nil + } + if lm.mounts == nil && lm.mountable != nil { mounts, release, err := lm.mountable.Mount() if err != nil { diff --git a/snapshot/localmounter_freebsd.go b/snapshot/localmounter_freebsd.go index 05db6c926..b0d008684 100644 --- a/snapshot/localmounter_freebsd.go +++ b/snapshot/localmounter_freebsd.go @@ -12,6 +12,10 @@ func (lm *localMounter) Mount() (string, error) { lm.mu.Lock() defer lm.mu.Unlock() + if lm.target != "" { + return lm.target, nil + } + if lm.mounts == nil && lm.mountable != nil { mounts, release, err := lm.mountable.Mount() if err != nil { diff --git a/snapshot/localmounter_linux.go b/snapshot/localmounter_linux.go index d188e5241..a8132c9a7 100644 --- a/snapshot/localmounter_linux.go +++ b/snapshot/localmounter_linux.go @@ -16,6 +16,10 @@ func (lm *localMounter) Mount() (string, error) { lm.mu.Lock() defer lm.mu.Unlock() + if lm.target != "" { + return lm.target, nil + } + if lm.mounts == nil && lm.mountable != nil { mounts, release, err := lm.mountable.Mount() if err != nil { diff --git a/snapshot/localmounter_windows.go b/snapshot/localmounter_windows.go index 0bb4df884..5169ba772 100644 --- a/snapshot/localmounter_windows.go +++ b/snapshot/localmounter_windows.go @@ -16,6 +16,10 @@ func (lm *localMounter) Mount() (string, error) { lm.mu.Lock() defer lm.mu.Unlock() + if lm.target != "" { + return lm.target, nil + } + if lm.mounts == nil && lm.mountable != nil { mounts, release, err := lm.mountable.Mount() if err != nil {