builder: fix duplicate mount release
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> (cherry picked from commit 2732fe527f9258561c7310c128914b4b456c8404) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 5853cd510c3272755ca5d6605ca8039d54a5ba15 Component: engine
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
1a55d345e4
commit
ea7e1c4aaa
@ -426,10 +426,11 @@ func (s *snapshotter) Close() error {
|
||||
}
|
||||
|
||||
type mountable struct {
|
||||
mu sync.Mutex
|
||||
mounts []mount.Mount
|
||||
acquire func() ([]mount.Mount, error)
|
||||
release func() error
|
||||
mu sync.Mutex
|
||||
mounts []mount.Mount
|
||||
acquire func() ([]mount.Mount, error)
|
||||
release func() error
|
||||
refCount int
|
||||
}
|
||||
|
||||
func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||
@ -437,6 +438,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||
defer m.mu.Unlock()
|
||||
|
||||
if m.mounts != nil {
|
||||
m.refCount++
|
||||
return m.mounts, nil
|
||||
}
|
||||
|
||||
@ -445,6 +447,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||
return nil, err
|
||||
}
|
||||
m.mounts = mounts
|
||||
m.refCount = 1
|
||||
|
||||
return m.mounts, nil
|
||||
}
|
||||
@ -452,6 +455,13 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||
func (m *mountable) Release() error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
if m.refCount > 1 {
|
||||
m.refCount--
|
||||
return nil
|
||||
}
|
||||
|
||||
m.refCount = 0
|
||||
if m.release == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user