1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix issue with multiple volume refs with same name

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 0fe31306d1)
This commit is contained in:
Brian Goff 2016-02-16 21:10:45 -05:00 committed by Tibor Vass
parent 77f94fd3c5
commit 7ad7f263d7
2 changed files with 24 additions and 7 deletions

View file

@ -291,16 +291,14 @@ func (s *VolumeStore) Dereference(v volume.Volume, ref string) {
s.globalLock.Lock()
defer s.globalLock.Unlock()
refs, exists := s.refs[v.Name()]
if !exists {
return
}
var refs []string
for i, r := range refs {
if r == ref {
s.refs[v.Name()] = append(s.refs[v.Name()][:i], s.refs[v.Name()][i+1:]...)
for _, r := range s.refs[v.Name()] {
if r != ref {
refs = append(refs, r)
}
}
s.refs[v.Name()] = refs
}
// Refs gets the current list of refs for the given volume

View file

@ -157,3 +157,22 @@ func TestFilterByUsed(t *testing.T) {
t.Fatalf("expected used volume fake1, got %s", used[0].Name())
}
}
func TestDerefMultipleOfSameRef(t *testing.T) {
volumedrivers.Register(vt.NewFakeDriver("fake"), "fake")
s := New()
v, err := s.CreateWithRef("fake1", "fake", "volReference", nil)
if err != nil {
t.Fatal(err)
}
if _, err := s.GetWithRef("fake1", "fake", "volReference"); err != nil {
t.Fatal(err)
}
s.Dereference(v, "volReference")
if err := s.Remove(v); err != nil {
t.Fatal(err)
}
}