mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
builder: fix duplicate mount release
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
f7e5154f37
commit
2732fe527f
1 changed files with 14 additions and 4 deletions
|
@ -430,6 +430,7 @@ type mountable struct {
|
||||||
mounts []mount.Mount
|
mounts []mount.Mount
|
||||||
acquire func() ([]mount.Mount, error)
|
acquire func() ([]mount.Mount, error)
|
||||||
release func() error
|
release func() error
|
||||||
|
refCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mountable) Mount() ([]mount.Mount, error) {
|
func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||||
|
@ -437,6 +438,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
if m.mounts != nil {
|
if m.mounts != nil {
|
||||||
|
m.refCount++
|
||||||
return m.mounts, nil
|
return m.mounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,6 +447,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.mounts = mounts
|
m.mounts = mounts
|
||||||
|
m.refCount = 1
|
||||||
|
|
||||||
return m.mounts, nil
|
return m.mounts, nil
|
||||||
}
|
}
|
||||||
|
@ -452,6 +455,13 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
|
||||||
func (m *mountable) Release() error {
|
func (m *mountable) Release() error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.refCount > 1 {
|
||||||
|
m.refCount--
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
m.refCount = 0
|
||||||
if m.release == nil {
|
if m.release == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue