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

Merge pull request #8799 from jlhawn/remove_jsondata_arg

Remove `jsonData` argument from `image.StoreImage`
This commit is contained in:
Tibor Vass 2014-11-03 20:55:40 -05:00
commit 5b03a21963
7 changed files with 23 additions and 29 deletions

View file

@ -132,14 +132,14 @@ func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, contain
img.ContainerConfig = *containerConfig img.ContainerConfig = *containerConfig
} }
if err := graph.Register(img, nil, layerData); err != nil { if err := graph.Register(img, 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.
func (graph *Graph) Register(img *image.Image, jsonData []byte, layerData archive.ArchiveReader) (err error) { func (graph *Graph) Register(img *image.Image, layerData archive.ArchiveReader) (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.
@ -181,7 +181,7 @@ func (graph *Graph) Register(img *image.Image, jsonData []byte, layerData archiv
} }
// Apply the diff/layer // Apply the diff/layer
img.SetGraph(graph) img.SetGraph(graph)
if err := image.StoreImage(img, jsonData, layerData, tmp); err != nil { if err := image.StoreImage(img, layerData, tmp); err != nil {
return err return err
} }
// Commit // Commit

View file

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

View file

@ -394,7 +394,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
layers_downloaded = true layers_downloaded = true
defer layer.Close() defer layer.Close()
err = s.graph.Register(img, imgJSON, err = s.graph.Register(img,
utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading")) utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading"))
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)
@ -579,7 +579,7 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri
defer d.tmpFile.Close() defer d.tmpFile.Close()
d.tmpFile.Seek(0, 0) d.tmpFile.Seek(0, 0)
if d.tmpFile != nil { if d.tmpFile != nil {
err = s.graph.Register(d.img, d.imgJSON, err = s.graph.Register(d.img,
utils.ProgressReader(d.tmpFile, int(d.length), out, sf, false, utils.TruncateID(d.img.ID), "Extracting")) utils.ProgressReader(d.tmpFile, int(d.length), out, sf, false, utils.TruncateID(d.img.ID), "Extracting"))
if err != nil { if err != nil {
return false, err return false, err

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(img, imgJSON, layer); err != nil { if err := s.graph.Register(img, layer); err != nil {
return job.Error(err) return job.Error(err)
} }
return engine.StatusOK return engine.StatusOK

View file

@ -62,7 +62,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(img, nil, archive); err != nil { if err := graph.Register(img, 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

@ -70,7 +70,7 @@ func LoadImage(root string) (*Image, error) {
return img, nil return img, nil
} }
func StoreImage(img *Image, jsonData []byte, layerData archive.ArchiveReader, root string) error { func StoreImage(img *Image, layerData archive.ArchiveReader, root string) error {
// Store the layer // Store the layer
var ( var (
size int64 size int64
@ -90,20 +90,14 @@ func StoreImage(img *Image, jsonData []byte, layerData archive.ArchiveReader, ro
return err return err
} }
// If raw json is provided, then use it f, err := os.OpenFile(jsonPath(root), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
if jsonData != nil { if err != nil {
if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil { return err
return err
}
} else {
if jsonData, err = json.Marshal(img); err != nil {
return err
}
if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil {
return err
}
} }
return nil
defer f.Close()
return json.NewEncoder(f).Encode(img)
} }
func (img *Image) SetGraph(graph Graph) { func (img *Image) SetGraph(graph Graph) {

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(image, nil, badArchive) graph.Register(image, 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(image, nil, goodArchive); err != nil { if err := graph.Register(image, 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(image, nil, archive) err = graph.Register(image, 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(img1, nil, archive); err != nil { if err := graph.Register(img1, 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(parentImage, nil, archive1) _ = graph.Register(parentImage, archive1)
_ = graph.Register(childImage1, nil, archive2) _ = graph.Register(childImage1, archive2)
_ = graph.Register(childImage2, nil, archive3) _ = graph.Register(childImage2, archive3)
byParent, err := graph.ByParent() byParent, err := graph.ByParent()
if err != nil { if err != nil {