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

graph: change argument order of Register function

This commit is patch for following comment
FIXME: pass img as first argument

Signed-off-by: Daehyeok.Mun <daehyeok@gmail.com>
This commit is contained in:
Daehyeok.Mun 2014-08-28 19:57:54 +09:00
parent 22b585e0fc
commit 35df24c8e6
6 changed files with 14 additions and 16 deletions

View file

@ -151,15 +151,14 @@ func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, contain
img.ContainerConfig = *containerConfig img.ContainerConfig = *containerConfig
} }
if err := graph.Register(nil, layerData, img); err != nil { if err := graph.Register(img, nil, layerData); err != nil {
return nil, err return nil, err
} }
return img, nil return img, nil
} }
// Register imports a pre-existing image into the graph. // Register imports a pre-existing image into the graph.
// FIXME: pass img as first argument func (graph *Graph) Register(img *image.Image, jsonData []byte, layerData archive.ArchiveReader) (err error) {
func (graph *Graph) Register(jsonData []byte, layerData archive.ArchiveReader, img *image.Image) (err error) {
defer func() { defer func() {
// If any error occurs, remove the new dir from the driver. // If any error occurs, remove the new dir from the driver.
// Don't check for errors since the dir might not have been created. // Don't check for errors since the dir might not have been created.

View file

@ -118,7 +118,7 @@ func (s *TagStore) recursiveLoad(eng *engine.Engine, address, tmpImageDir string
} }
} }
} }
if err := s.graph.Register(imageJson, layer, img); err != nil { if err := s.graph.Register(img, imageJson, layer); err != nil {
return err return err
} }
} }

View file

@ -280,9 +280,8 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
} }
defer layer.Close() defer layer.Close()
err = s.graph.Register(imgJSON, err = s.graph.Register(img, imgJSON,
utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading"), utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading"))
img)
if terr, ok := err.(net.Error); ok && terr.Timeout() && j < retries { if terr, ok := err.(net.Error); ok && terr.Timeout() && j < retries {
time.Sleep(time.Duration(j) * 500 * time.Millisecond) time.Sleep(time.Duration(j) * 500 * time.Millisecond)
continue continue

View file

@ -74,7 +74,7 @@ func (s *TagStore) CmdSet(job *engine.Job) engine.Status {
if err != nil { if err != nil {
return job.Error(err) return job.Error(err)
} }
if err := s.graph.Register(imgJSON, layer, img); err != nil { if err := s.graph.Register(img, imgJSON, layer); err != nil {
return job.Error(err) return job.Error(err)
} }
return engine.StatusOK return engine.StatusOK

View file

@ -61,7 +61,7 @@ func mkTestTagStore(root string, t *testing.T) *TagStore {
t.Fatal(err) t.Fatal(err)
} }
img := &image.Image{ID: testImageID} img := &image.Image{ID: testImageID}
if err := graph.Register(nil, archive, img); err != nil { if err := graph.Register(img, nil, archive); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := store.Set(testImageName, "", testImageID, false); err != nil { if err := store.Set(testImageName, "", testImageID, false); err != nil {

View file

@ -74,7 +74,7 @@ func TestInterruptedRegister(t *testing.T) {
Created: time.Now(), Created: time.Now(),
} }
w.CloseWithError(errors.New("But I'm not a tarball!")) // (Nobody's perfect, darling) w.CloseWithError(errors.New("But I'm not a tarball!")) // (Nobody's perfect, darling)
graph.Register(nil, badArchive, image) graph.Register(image, nil, badArchive)
if _, err := graph.Get(image.ID); err == nil { if _, err := graph.Get(image.ID); err == nil {
t.Fatal("Image should not exist after Register is interrupted") t.Fatal("Image should not exist after Register is interrupted")
} }
@ -83,7 +83,7 @@ func TestInterruptedRegister(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := graph.Register(nil, goodArchive, image); err != nil { if err := graph.Register(image, nil, goodArchive); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -133,7 +133,7 @@ func TestRegister(t *testing.T) {
Comment: "testing", Comment: "testing",
Created: time.Now(), Created: time.Now(),
} }
err = graph.Register(nil, archive, image) err = graph.Register(image, nil, archive)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -228,7 +228,7 @@ func TestDelete(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Test delete twice (pull -> rm -> pull -> rm) // Test delete twice (pull -> rm -> pull -> rm)
if err := graph.Register(nil, archive, img1); err != nil { if err := graph.Register(img1, nil, archive); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := graph.Delete(img1.ID); err != nil { if err := graph.Delete(img1.ID); err != nil {
@ -262,9 +262,9 @@ func TestByParent(t *testing.T) {
Created: time.Now(), Created: time.Now(),
Parent: parentImage.ID, Parent: parentImage.ID,
} }
_ = graph.Register(nil, archive1, parentImage) _ = graph.Register(parentImage, nil, archive1)
_ = graph.Register(nil, archive2, childImage1) _ = graph.Register(childImage1, nil, archive2)
_ = graph.Register(nil, archive3, childImage2) _ = graph.Register(childImage2, nil, archive3)
byParent, err := graph.ByParent() byParent, err := graph.ByParent()
if err != nil { if err != nil {