Browse Source

graph: variablize file names

and add a comment.. :-)

Signed-off-by: Vincent Batts <vbatts@redhat.com>

Conflicts:
	graph/graph.go
Vincent Batts 10 years ago
parent
commit
ba1f76cbfa
3 changed files with 19 additions and 9 deletions
  1. 15 7
      graph/graph.go
  2. 2 1
      graph/graph_unix.go
  3. 2 1
      graph/graph_windows.go

+ 15 - 7
graph/graph.go

@@ -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
@@ -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
 		}
@@ -479,8 +487,8 @@ 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
 }
@@ -488,8 +496,8 @@ func (graph *Graph) saveSize(root string, size int) error {
 // 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
 }
@@ -497,7 +505,7 @@ func (graph *Graph) SetDigest(id string, dgst digest.Digest) error {
 // 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
@@ -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)
 }

+ 2 - 1
graph/graph_unix.go

@@ -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
 		}
@@ -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)
 }

+ 2 - 1
graph/graph_windows.go

@@ -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
 			}
@@ -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)
 	}
 }