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

Fix image deletion conflicts with search

Removed images were not cleaned up from the
digest-set that is used for the search index.

Fixes #18437

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2015-12-04 13:15:54 -08:00
parent 23f00624a1
commit fcb083c6ac
3 changed files with 44 additions and 2 deletions

View file

@ -212,6 +212,9 @@ func (is *store) Delete(id ID) ([]layer.Metadata, error) {
delete(is.images[parent].children, id)
}
if err := is.digestSet.Remove(digest.Digest(id)); err != nil {
logrus.Errorf("error removing %s from digest set: %q", id, err)
}
delete(is.images, id)
is.fs.Delete(id)

View file

@ -194,6 +194,45 @@ func TestAddDelete(t *testing.T) {
}
func TestSearchAfterDelete(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
if err != nil {
t.Fatal(err)
}
id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
if err != nil {
t.Fatal(err)
}
id1, err := is.Search(string(id)[:15])
if err != nil {
t.Fatal(err)
}
if actual, expected := id1, id; expected != actual {
t.Fatalf("wrong id returned from search: expected %q, got %q", expected, actual)
}
if _, err := is.Delete(id); err != nil {
t.Fatal(err)
}
if _, err := is.Search(string(id)[:15]); err == nil {
t.Fatal("expected search after deletion to fail")
}
}
type mockLayerGetReleaser struct{}
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {

View file

@ -348,11 +348,11 @@ func (s *DockerSuite) TestInspectByPrefix(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(id, checker.HasPrefix, "sha256:")
id2, err := inspectField(id[:10], "Id")
id2, err := inspectField(id[:12], "Id")
c.Assert(err, checker.IsNil)
c.Assert(id, checker.Equals, id2)
id3, err := inspectField(strings.TrimPrefix(id, "sha256:")[:10], "Id")
id3, err := inspectField(strings.TrimPrefix(id, "sha256:")[:12], "Id")
c.Assert(err, checker.IsNil)
c.Assert(id, checker.Equals, id3)
}