mirror of
https://github.com/containers/skopeo.git
synced 2025-06-28 15:47:34 +00:00
Use dirImageDestination for writing to local files in docker.go
This will hopefully allow better reuse of the "copy images" code from docker.go in the future. No behavior change, the dirImageDestination code was based on the code this commit is replacing.
This commit is contained in:
parent
af126bc68c
commit
fd41449410
21
docker.go
21
docker.go
@ -10,7 +10,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -415,11 +414,12 @@ func (i *dockerImage) Layers(layers ...string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
dest := NewDirImageDestination(tmpDir)
|
||||||
data, err := json.Marshal(m)
|
data, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(path.Join(tmpDir, "manifest.json"), data, 0644); err != nil {
|
if err := dest.PutManifest(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(layers) == 0 {
|
if len(layers) == 0 {
|
||||||
@ -429,31 +429,20 @@ func (i *dockerImage) Layers(layers ...string) error {
|
|||||||
if !strings.HasPrefix(l, "sha256:") {
|
if !strings.HasPrefix(l, "sha256:") {
|
||||||
l = "sha256:" + l
|
l = "sha256:" + l
|
||||||
}
|
}
|
||||||
if err := i.getLayer(l, tmpDir); err != nil {
|
if err := i.getLayer(dest, l); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *dockerImage) getLayer(digest, tmpDir string) error {
|
func (i *dockerImage) getLayer(dest types.ImageDestination, digest string) error {
|
||||||
stream, err := i.src.GetLayer(digest)
|
stream, err := i.src.GetLayer(digest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stream.Close()
|
defer stream.Close()
|
||||||
layerPath := path.Join(tmpDir, strings.Replace(digest, "sha256:", "", -1)+".tar")
|
return dest.PutLayer(digest, stream)
|
||||||
layerFile, err := os.Create(layerPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(layerFile, stream); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := layerFile.Sync(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newDockerImageSource is the same as NewDockerImageSource, only it returns the more specific *dockerImageSource type.
|
// newDockerImageSource is the same as NewDockerImageSource, only it returns the more specific *dockerImageSource type.
|
||||||
|
Loading…
Reference in New Issue
Block a user