Skip to content

Commit

Permalink
graph: variablize file names
Browse files Browse the repository at this point in the history
and add a comment.. :-)

Signed-off-by: Vincent Batts <[email protected]>

Conflicts:
	graph/graph.go
  • Loading branch information
vbatts committed Jul 22, 2015
1 parent 5d9f065 commit ba1f76c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
22 changes: 15 additions & 7 deletions graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ type Graph struct {
retained *retainedLayers
}

// file names for ./graph/<ID>/
const (
jsonFileName = "json"
layersizeFileName = "layersize"
digestFileName = "checksum"
tardataFileName = "tar-data.json.gz"
)

var (
// ErrDigestNotSet is used when request the digest for a layer
// but the layer has no digest value or content to compute the
Expand Down Expand Up @@ -456,7 +464,7 @@ func (graph *Graph) loadImage(id string) (*image.Image, error) {
return nil, err
}

if buf, err := ioutil.ReadFile(filepath.Join(root, "layersize")); err != nil {
if buf, err := ioutil.ReadFile(filepath.Join(root, layersizeFileName)); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
Expand All @@ -479,25 +487,25 @@ func (graph *Graph) loadImage(id string) (*image.Image, error) {

// saveSize stores the `size` in the provided graph `img` directory `root`.
func (graph *Graph) saveSize(root string, size int) error {
if err := ioutil.WriteFile(filepath.Join(root, "layersize"), []byte(strconv.Itoa(size)), 0600); err != nil {
return fmt.Errorf("Error storing image size in %s/layersize: %s", root, err)
if err := ioutil.WriteFile(filepath.Join(root, layersizeFileName), []byte(strconv.Itoa(size)), 0600); err != nil {
return fmt.Errorf("Error storing image size in %s/%s: %s", root, layersizeFileName, err)
}
return nil
}

// SetDigest sets the digest for the image layer to the provided value.
func (graph *Graph) SetDigest(id string, dgst digest.Digest) error {
root := graph.imageRoot(id)
if err := ioutil.WriteFile(filepath.Join(root, "checksum"), []byte(dgst.String()), 0600); err != nil {
return fmt.Errorf("Error storing digest in %s/checksum: %s", root, err)
if err := ioutil.WriteFile(filepath.Join(root, digestFileName), []byte(dgst.String()), 0600); err != nil {
return fmt.Errorf("Error storing digest in %s/%s: %s", root, digestFileName, err)
}
return nil
}

// GetDigest gets the digest for the provide image layer id.
func (graph *Graph) GetDigest(id string) (digest.Digest, error) {
root := graph.imageRoot(id)
cs, err := ioutil.ReadFile(filepath.Join(root, "checksum"))
cs, err := ioutil.ReadFile(filepath.Join(root, digestFileName))
if err != nil {
if os.IsNotExist(err) {
return "", ErrDigestNotSet
Expand All @@ -520,5 +528,5 @@ func (graph *Graph) RawJSON(id string) ([]byte, error) {
}

func jsonPath(root string) string {
return filepath.Join(root, "json")
return filepath.Join(root, jsonFileName)
}
3 changes: 2 additions & 1 deletion graph/graph_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (graph *Graph) storeImage(img *image.Image, layerData archive.ArchiveReader
// Store the layer. If layerData is not nil, unpack it into the new layer
if layerData != nil {
// this is saving the tar-split metadata
mf, err := os.OpenFile(filepath.Join(root, "tar-data.json.gz"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
mf, err := os.OpenFile(filepath.Join(root, tardataFileName), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
if err != nil {
return err
}
Expand Down Expand Up @@ -134,5 +134,6 @@ func (graph *Graph) storeImage(img *image.Image, layerData archive.ArchiveReader

// TarLayer returns a tar archive of the image's filesystem layer.
func (graph *Graph) TarLayer(img *image.Image) (arch archive.Archive, err error) {
// TODO(vbatts) let's reassemble!
return graph.driver.Diff(img.ID, img.Parent)
}
3 changes: 2 additions & 1 deletion graph/graph_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (graph *Graph) storeImage(img *image.Image, layerData archive.ArchiveReader
// Store the layer. If layerData is not nil, unpack it into the new layer
if layerData != nil {
// this is saving the tar-split metadata
mf, err := os.OpenFile(filepath.Join(root, "tar-data.json.gz"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
mf, err := os.OpenFile(filepath.Join(root, tardataFileName), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
if err != nil {
return err
}
Expand Down Expand Up @@ -180,6 +180,7 @@ func (graph *Graph) TarLayer(img *image.Image) (arch archive.Archive, err error)
// We keep this functionality here so that we can still work with the VFS
// driver during development. VFS is not supported (and just will not work)
// for Windows containers.
// TODO(vbatts) let's reassemble!
return graph.driver.Diff(img.ID, img.Parent)
}
}

0 comments on commit ba1f76c

Please sign in to comment.