فهرست منبع

Merge pull request #17810 from cpuguy83/graph_cleanup

Graph: Un-export non-externally used functions
David Calavera 9 سال پیش
والد
کامیت
0631ec6ca0
14فایلهای تغییر یافته به همراه79 افزوده شده و 105 حذف شده
  1. 3 3
      graph/export.go
  2. 19 44
      graph/graph.go
  3. 6 6
      graph/history.go
  4. 3 3
      graph/list.go
  5. 1 1
      graph/load.go
  6. 5 5
      graph/pull.go
  7. 4 4
      graph/pull_v2.go
  8. 5 5
      graph/push.go
  9. 3 3
      graph/push_v1.go
  10. 7 7
      graph/push_v2.go
  11. 4 3
      graph/registry.go
  12. 4 4
      graph/service.go
  13. 14 16
      graph/tags.go
  14. 1 1
      graph/tags_unit_test.go

+ 3 - 3
graph/export.go

@@ -29,11 +29,11 @@ func (s *TagStore) ImageExport(names []string, outStream io.Writer) error {
 	}
 	}
 	defer os.RemoveAll(tempdir)
 	defer os.RemoveAll(tempdir)
 
 
-	rootRepoMap := map[string]Repository{}
+	rootRepoMap := map[string]repository{}
 	addKey := func(name string, tag string, id string) {
 	addKey := func(name string, tag string, id string) {
 		logrus.Debugf("add key [%s:%s]", name, tag)
 		logrus.Debugf("add key [%s:%s]", name, tag)
 		if repo, ok := rootRepoMap[name]; !ok {
 		if repo, ok := rootRepoMap[name]; !ok {
-			rootRepoMap[name] = Repository{tag: id}
+			rootRepoMap[name] = repository{tag: id}
 		} else {
 		} else {
 			repo[tag] = id
 			repo[tag] = id
 		}
 		}
@@ -163,7 +163,7 @@ func (s *TagStore) exportImage(name, tempdir string) error {
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
-		if err := s.ImageTarLayer(n, fsTar); err != nil {
+		if err := s.imageTarLayer(n, fsTar); err != nil {
 			return err
 			return err
 		}
 		}
 
 

+ 19 - 44
graph/graph.go

@@ -123,10 +123,10 @@ const (
 )
 )
 
 
 var (
 var (
-	// ErrDigestNotSet is used when request the digest for a layer
+	// errDigestNotSet is used when request the digest for a layer
 	// but the layer has no digest value or content to compute the
 	// but the layer has no digest value or content to compute the
 	// the digest.
 	// the digest.
-	ErrDigestNotSet = errors.New("digest is not set for layer")
+	errDigestNotSet = errors.New("digest is not set for layer")
 )
 )
 
 
 // NewGraph instantiates a new graph at the given root path in the filesystem.
 // NewGraph instantiates a new graph at the given root path in the filesystem.
@@ -368,7 +368,7 @@ func createRootFilesystemInDriver(graph *Graph, id, parent string) error {
 // TempLayerArchive creates a temporary archive of the given image's filesystem layer.
 // TempLayerArchive creates a temporary archive of the given image's filesystem layer.
 //   The archive is stored on disk and will be automatically deleted as soon as has been read.
 //   The archive is stored on disk and will be automatically deleted as soon as has been read.
 //   If output is not nil, a human-readable progress bar will be written to it.
 //   If output is not nil, a human-readable progress bar will be written to it.
-func (graph *Graph) TempLayerArchive(id string, sf *streamformatter.StreamFormatter, output io.Writer) (*archive.TempArchive, error) {
+func (graph *Graph) tempLayerArchive(id string, sf *streamformatter.StreamFormatter, output io.Writer) (*archive.TempArchive, error) {
 	image, err := graph.Get(id)
 	image, err := graph.Get(id)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
@@ -378,7 +378,7 @@ func (graph *Graph) TempLayerArchive(id string, sf *streamformatter.StreamFormat
 		return nil, err
 		return nil, err
 	}
 	}
 	defer os.RemoveAll(tmp)
 	defer os.RemoveAll(tmp)
-	a, err := graph.TarLayer(image)
+	a, err := graph.tarLayer(image)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -505,9 +505,9 @@ func (graph *Graph) Release(sessionID string, layerIDs ...string) {
 	graph.retained.Delete(sessionID, layerIDs)
 	graph.retained.Delete(sessionID, layerIDs)
 }
 }
 
 
-// Heads returns all heads in the graph, keyed by id.
+// heads returns all heads in the graph, keyed by id.
 // A head is an image which is not the parent of another image in the graph.
 // A head is an image which is not the parent of another image in the graph.
-func (graph *Graph) Heads() map[string]*image.Image {
+func (graph *Graph) heads() map[string]*image.Image {
 	heads := make(map[string]*image.Image)
 	heads := make(map[string]*image.Image)
 	graph.walkAll(func(image *image.Image) {
 	graph.walkAll(func(image *image.Image) {
 		// if it has no children, then it's not a parent, so it's an head
 		// if it has no children, then it's not a parent, so it's an head
@@ -518,11 +518,11 @@ func (graph *Graph) Heads() map[string]*image.Image {
 	return heads
 	return heads
 }
 }
 
 
-// TarLayer returns a tar archive of the image's filesystem layer.
-func (graph *Graph) TarLayer(img *image.Image) (arch io.ReadCloser, err error) {
+// tarLayer returns a tar archive of the image's filesystem layer.
+func (graph *Graph) tarLayer(img *image.Image) (arch io.ReadCloser, err error) {
 	rdr, err := graph.assembleTarLayer(img)
 	rdr, err := graph.assembleTarLayer(img)
 	if err != nil {
 	if err != nil {
-		logrus.Debugf("[graph] TarLayer with traditional differ: %s", img.ID)
+		logrus.Debugf("[graph] tarLayer with traditional differ: %s", img.ID)
 		return graph.driver.Diff(img.ID, img.Parent)
 		return graph.driver.Diff(img.ID, img.Parent)
 	}
 	}
 	return rdr, nil
 	return rdr, nil
@@ -598,8 +598,8 @@ func (graph *Graph) saveSize(root string, size int64) error {
 	return nil
 	return nil
 }
 }
 
 
-// SetLayerDigest sets the digest for the image layer to the provided value.
-func (graph *Graph) SetLayerDigest(id string, dgst digest.Digest) error {
+// setLayerDigestWithLock sets the digest for the image layer to the provided value.
+func (graph *Graph) setLayerDigestWithLock(id string, dgst digest.Digest) error {
 	graph.imageMutex.Lock(id)
 	graph.imageMutex.Lock(id)
 	defer graph.imageMutex.Unlock(id)
 	defer graph.imageMutex.Unlock(id)
 
 
@@ -613,8 +613,8 @@ func (graph *Graph) setLayerDigest(id string, dgst digest.Digest) error {
 	return nil
 	return nil
 }
 }
 
 
-// GetLayerDigest gets the digest for the provide image layer id.
-func (graph *Graph) GetLayerDigest(id string) (digest.Digest, error) {
+// getLayerDigestWithLock gets the digest for the provide image layer id.
+func (graph *Graph) getLayerDigestWithLock(id string) (digest.Digest, error) {
 	graph.imageMutex.Lock(id)
 	graph.imageMutex.Lock(id)
 	defer graph.imageMutex.Unlock(id)
 	defer graph.imageMutex.Unlock(id)
 
 
@@ -626,44 +626,31 @@ func (graph *Graph) getLayerDigest(id string) (digest.Digest, error) {
 	cs, err := ioutil.ReadFile(filepath.Join(root, digestFileName))
 	cs, err := ioutil.ReadFile(filepath.Join(root, digestFileName))
 	if err != nil {
 	if err != nil {
 		if os.IsNotExist(err) {
 		if os.IsNotExist(err) {
-			return "", ErrDigestNotSet
+			return "", errDigestNotSet
 		}
 		}
 		return "", err
 		return "", err
 	}
 	}
 	return digest.ParseDigest(string(cs))
 	return digest.ParseDigest(string(cs))
 }
 }
 
 
-// SetV1CompatibilityConfig stores the v1Compatibility JSON data associated
+// setV1CompatibilityConfig stores the v1Compatibility JSON data associated
 // with the image in the manifest to the disk
 // with the image in the manifest to the disk
-func (graph *Graph) SetV1CompatibilityConfig(id string, data []byte) error {
-	graph.imageMutex.Lock(id)
-	defer graph.imageMutex.Unlock(id)
-
-	return graph.setV1CompatibilityConfig(id, data)
-}
 func (graph *Graph) setV1CompatibilityConfig(id string, data []byte) error {
 func (graph *Graph) setV1CompatibilityConfig(id string, data []byte) error {
 	root := graph.imageRoot(id)
 	root := graph.imageRoot(id)
 	return ioutil.WriteFile(filepath.Join(root, v1CompatibilityFileName), data, 0600)
 	return ioutil.WriteFile(filepath.Join(root, v1CompatibilityFileName), data, 0600)
 }
 }
 
 
-// GetV1CompatibilityConfig reads the v1Compatibility JSON data for the image
+// getV1CompatibilityConfig reads the v1Compatibility JSON data for the image
 // from the disk
 // from the disk
-func (graph *Graph) GetV1CompatibilityConfig(id string) ([]byte, error) {
-	graph.imageMutex.Lock(id)
-	defer graph.imageMutex.Unlock(id)
-
-	return graph.getV1CompatibilityConfig(id)
-}
-
 func (graph *Graph) getV1CompatibilityConfig(id string) ([]byte, error) {
 func (graph *Graph) getV1CompatibilityConfig(id string) ([]byte, error) {
 	root := graph.imageRoot(id)
 	root := graph.imageRoot(id)
 	return ioutil.ReadFile(filepath.Join(root, v1CompatibilityFileName))
 	return ioutil.ReadFile(filepath.Join(root, v1CompatibilityFileName))
 }
 }
 
 
-// GenerateV1CompatibilityChain makes sure v1Compatibility JSON data exists
+// generateV1CompatibilityChain makes sure v1Compatibility JSON data exists
 // for the image. If it doesn't it generates and stores it for the image and
 // for the image. If it doesn't it generates and stores it for the image and
 // all of it's parents based on the image config JSON.
 // all of it's parents based on the image config JSON.
-func (graph *Graph) GenerateV1CompatibilityChain(id string) ([]byte, error) {
+func (graph *Graph) generateV1CompatibilityChain(id string) ([]byte, error) {
 	graph.imageMutex.Lock(id)
 	graph.imageMutex.Lock(id)
 	defer graph.imageMutex.Unlock(id)
 	defer graph.imageMutex.Unlock(id)
 
 
@@ -681,7 +668,7 @@ func (graph *Graph) GenerateV1CompatibilityChain(id string) ([]byte, error) {
 	img.ID = strings.TrimPrefix(img.ID, digestPrefix)
 	img.ID = strings.TrimPrefix(img.ID, digestPrefix)
 
 
 	if img.Parent != "" {
 	if img.Parent != "" {
-		parentConfig, err := graph.GenerateV1CompatibilityChain(img.Parent)
+		parentConfig, err := graph.generateV1CompatibilityChain(img.Parent)
 		if err != nil {
 		if err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
@@ -703,18 +690,6 @@ func (graph *Graph) GenerateV1CompatibilityChain(id string) ([]byte, error) {
 	return json, nil
 	return json, nil
 }
 }
 
 
-// RawJSON returns the JSON representation for an image as a byte array.
-func (graph *Graph) RawJSON(id string) ([]byte, error) {
-	root := graph.imageRoot(id)
-
-	buf, err := ioutil.ReadFile(jsonPath(root))
-	if err != nil {
-		return nil, fmt.Errorf("Failed to read json for image %s: %s", id, err)
-	}
-
-	return buf, nil
-}
-
 func jsonPath(root string) string {
 func jsonPath(root string) string {
 	return filepath.Join(root, jsonFileName)
 	return filepath.Join(root, jsonFileName)
 }
 }

+ 6 - 6
graph/history.go

@@ -9,9 +9,9 @@ import (
 	"github.com/docker/docker/utils"
 	"github.com/docker/docker/utils"
 )
 )
 
 
-// WalkHistory calls the handler function for each image in the
+// walkHistory calls the handler function for each image in the
 // provided images lineage starting from immediate parent.
 // provided images lineage starting from immediate parent.
-func (graph *Graph) WalkHistory(img *image.Image, handler func(image.Image) error) (err error) {
+func (graph *Graph) walkHistory(img *image.Image, handler func(image.Image) error) (err error) {
 	currentImg := img
 	currentImg := img
 	for currentImg != nil {
 	for currentImg != nil {
 		if handler != nil {
 		if handler != nil {
@@ -85,7 +85,7 @@ func (s *TagStore) History(name string) ([]*types.ImageHistory, error) {
 
 
 	history := []*types.ImageHistory{}
 	history := []*types.ImageHistory{}
 
 
-	err = s.graph.WalkHistory(foundImage, func(img image.Image) error {
+	err = s.graph.walkHistory(foundImage, func(img image.Image) error {
 		history = append(history, &types.ImageHistory{
 		history = append(history, &types.ImageHistory{
 			ID:        img.ID,
 			ID:        img.ID,
 			Created:   img.Created.Unix(),
 			Created:   img.Created.Unix(),
@@ -108,12 +108,12 @@ func (graph *Graph) GetParent(img *image.Image) (*image.Image, error) {
 	return graph.Get(img.Parent)
 	return graph.Get(img.Parent)
 }
 }
 
 
-// GetParentsSize returns the combined size of all parent images. If there is
+// getParentsSize returns the combined size of all parent images. If there is
 // no parent image or it's unavailable, it returns 0.
 // no parent image or it's unavailable, it returns 0.
-func (graph *Graph) GetParentsSize(img *image.Image) int64 {
+func (graph *Graph) getParentsSize(img *image.Image) int64 {
 	parentImage, err := graph.GetParent(img)
 	parentImage, err := graph.GetParent(img)
 	if err != nil || parentImage == nil {
 	if err != nil || parentImage == nil {
 		return 0
 		return 0
 	}
 	}
-	return parentImage.Size + graph.GetParentsSize(parentImage)
+	return parentImage.Size + graph.getParentsSize(parentImage)
 }
 }

+ 3 - 3
graph/list.go

@@ -64,7 +64,7 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image,
 	if all && filtTagged {
 	if all && filtTagged {
 		allImages = s.graph.Map()
 		allImages = s.graph.Map()
 	} else {
 	} else {
-		allImages = s.graph.Heads()
+		allImages = s.graph.heads()
 	}
 	}
 
 
 	lookup := make(map[string]*types.Image)
 	lookup := make(map[string]*types.Image)
@@ -122,7 +122,7 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image,
 					}
 					}
 				}
 				}
 				if filtTagged {
 				if filtTagged {
-					newImage := newImage(image, s.graph.GetParentsSize(image))
+					newImage := newImage(image, s.graph.getParentsSize(image))
 
 
 					if utils.DigestReference(ref) {
 					if utils.DigestReference(ref) {
 						newImage.RepoTags = []string{}
 						newImage.RepoTags = []string{}
@@ -158,7 +158,7 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image,
 					continue
 					continue
 				}
 				}
 			}
 			}
-			newImage := newImage(image, s.graph.GetParentsSize(image))
+			newImage := newImage(image, s.graph.getParentsSize(image))
 			newImage.RepoTags = []string{"<none>:<none>"}
 			newImage.RepoTags = []string{"<none>:<none>"}
 			newImage.RepoDigests = []string{"<none>@<none>"}
 			newImage.RepoDigests = []string{"<none>@<none>"}
 
 

+ 1 - 1
graph/load.go

@@ -64,7 +64,7 @@ func (s *TagStore) Load(inTar io.ReadCloser, outStream io.Writer) error {
 	}
 	}
 	defer reposJSONFile.Close()
 	defer reposJSONFile.Close()
 
 
-	repositories := map[string]Repository{}
+	repositories := map[string]repository{}
 	if err := json.NewDecoder(reposJSONFile).Decode(&repositories); err != nil {
 	if err := json.NewDecoder(reposJSONFile).Decode(&repositories); err != nil {
 		return err
 		return err
 	}
 	}

+ 5 - 5
graph/pull.go

@@ -24,8 +24,8 @@ type ImagePullConfig struct {
 	OutStream io.Writer
 	OutStream io.Writer
 }
 }
 
 
-// Puller is an interface that abstracts pulling for different API versions.
-type Puller interface {
+// puller is an interface that abstracts pulling for different API versions.
+type puller interface {
 	// Pull tries to pull the image referenced by `tag`
 	// Pull tries to pull the image referenced by `tag`
 	// Pull returns an error if any, as well as a boolean that determines whether to retry Pull on the next configured endpoint.
 	// Pull returns an error if any, as well as a boolean that determines whether to retry Pull on the next configured endpoint.
 	//
 	//
@@ -33,12 +33,12 @@ type Puller interface {
 	Pull(tag string) (fallback bool, err error)
 	Pull(tag string) (fallback bool, err error)
 }
 }
 
 
-// NewPuller returns a Puller interface that will pull from either a v1 or v2
+// newPuller returns a Puller interface that will pull from either a v1 or v2
 // registry. The endpoint argument contains a Version field that determines
 // registry. The endpoint argument contains a Version field that determines
 // whether a v1 or v2 puller will be created. The other parameters are passed
 // whether a v1 or v2 puller will be created. The other parameters are passed
 // through to the underlying puller implementation for use during the actual
 // through to the underlying puller implementation for use during the actual
 // pull operation.
 // pull operation.
-func NewPuller(s *TagStore, endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, imagePullConfig *ImagePullConfig, sf *streamformatter.StreamFormatter) (Puller, error) {
+func newPuller(s *TagStore, endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, imagePullConfig *ImagePullConfig, sf *streamformatter.StreamFormatter) (puller, error) {
 	switch endpoint.Version {
 	switch endpoint.Version {
 	case registry.APIVersion2:
 	case registry.APIVersion2:
 		return &v2Puller{
 		return &v2Puller{
@@ -101,7 +101,7 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
 	for _, endpoint := range endpoints {
 	for _, endpoint := range endpoints {
 		logrus.Debugf("Trying to pull %s from %s %s", repoInfo.LocalName, endpoint.URL, endpoint.Version)
 		logrus.Debugf("Trying to pull %s from %s %s", repoInfo.LocalName, endpoint.URL, endpoint.Version)
 
 
-		puller, err := NewPuller(s, endpoint, repoInfo, imagePullConfig, sf)
+		puller, err := newPuller(s, endpoint, repoInfo, imagePullConfig, sf)
 		if err != nil {
 		if err != nil {
 			lastErr = err
 			lastErr = err
 			continue
 			continue

+ 4 - 4
graph/pull_v2.go

@@ -34,7 +34,7 @@ type v2Puller struct {
 
 
 func (p *v2Puller) Pull(tag string) (fallback bool, err error) {
 func (p *v2Puller) Pull(tag string) (fallback bool, err error) {
 	// TODO(tiborvass): was ReceiveTimeout
 	// TODO(tiborvass): was ReceiveTimeout
-	p.repo, err = NewV2Repository(p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "pull")
+	p.repo, err = newV2Repository(p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "pull")
 	if err != nil {
 	if err != nil {
 		logrus.Warnf("Error getting v2 registry: %v", err)
 		logrus.Warnf("Error getting v2 registry: %v", err)
 		return true, err
 		return true, err
@@ -404,7 +404,7 @@ func (p *v2Puller) pullV2Tag(out io.Writer, tag, taggedName string) (tagUpdated
 
 
 	// Check for new tag if no layers downloaded
 	// Check for new tag if no layers downloaded
 	if !tagUpdated {
 	if !tagUpdated {
-		repo, err := p.Get(p.repoInfo.LocalName)
+		repo, err := p.get(p.repoInfo.LocalName)
 		if err != nil {
 		if err != nil {
 			return false, err
 			return false, err
 		}
 		}
@@ -423,7 +423,7 @@ func (p *v2Puller) pullV2Tag(out io.Writer, tag, taggedName string) (tagUpdated
 		// use the digest whether we pull by it or not. Unfortunately, the tag
 		// use the digest whether we pull by it or not. Unfortunately, the tag
 		// store treats the digest as a separate tag, meaning there may be an
 		// store treats the digest as a separate tag, meaning there may be an
 		// untagged digest image that would seem to be dangling by a user.
 		// untagged digest image that would seem to be dangling by a user.
-		if err = p.SetDigest(p.repoInfo.LocalName, tag, firstID); err != nil {
+		if err = p.setDigest(p.repoInfo.LocalName, tag, firstID); err != nil {
 			return false, err
 			return false, err
 		}
 		}
 	} else {
 	} else {
@@ -570,7 +570,7 @@ func (p *v2Puller) attemptIDReuse(imgs []contentAddressableDescriptor) {
 		idMap[img.compatibilityID] = struct{}{}
 		idMap[img.compatibilityID] = struct{}{}
 
 
 		if p.graph.Exists(img.compatibilityID) {
 		if p.graph.Exists(img.compatibilityID) {
-			if _, err := p.graph.GenerateV1CompatibilityChain(img.compatibilityID); err != nil {
+			if _, err := p.graph.generateV1CompatibilityChain(img.compatibilityID); err != nil {
 				logrus.Debugf("Migration v1Compatibility generation error: %v", err)
 				logrus.Debugf("Migration v1Compatibility generation error: %v", err)
 				return
 				return
 			}
 			}

+ 5 - 5
graph/push.go

@@ -27,8 +27,8 @@ type ImagePushConfig struct {
 	OutStream io.Writer
 	OutStream io.Writer
 }
 }
 
 
-// Pusher is an interface that abstracts pushing for different API versions.
-type Pusher interface {
+// pusher is an interface that abstracts pushing for different API versions.
+type pusher interface {
 	// Push tries to push the image configured at the creation of Pusher.
 	// Push tries to push the image configured at the creation of Pusher.
 	// Push returns an error if any, as well as a boolean that determines whether to retry Push on the next configured endpoint.
 	// Push returns an error if any, as well as a boolean that determines whether to retry Push on the next configured endpoint.
 	//
 	//
@@ -36,12 +36,12 @@ type Pusher interface {
 	Push() (fallback bool, err error)
 	Push() (fallback bool, err error)
 }
 }
 
 
-// NewPusher creates a new Pusher interface that will push to either a v1 or v2
+// newPusher creates a new Pusher interface that will push to either a v1 or v2
 // registry. The endpoint argument contains a Version field that determines
 // registry. The endpoint argument contains a Version field that determines
 // whether a v1 or v2 pusher will be created. The other parameters are passed
 // whether a v1 or v2 pusher will be created. The other parameters are passed
 // through to the underlying pusher implementation for use during the actual
 // through to the underlying pusher implementation for use during the actual
 // push operation.
 // push operation.
-func (s *TagStore) NewPusher(endpoint registry.APIEndpoint, localRepo Repository, repoInfo *registry.RepositoryInfo, imagePushConfig *ImagePushConfig, sf *streamformatter.StreamFormatter) (Pusher, error) {
+func (s *TagStore) newPusher(endpoint registry.APIEndpoint, localRepo repository, repoInfo *registry.RepositoryInfo, imagePushConfig *ImagePushConfig, sf *streamformatter.StreamFormatter) (pusher, error) {
 	switch endpoint.Version {
 	switch endpoint.Version {
 	case registry.APIVersion2:
 	case registry.APIVersion2:
 		return &v2Pusher{
 		return &v2Pusher{
@@ -100,7 +100,7 @@ func (s *TagStore) Push(localName string, imagePushConfig *ImagePushConfig) erro
 	for _, endpoint := range endpoints {
 	for _, endpoint := range endpoints {
 		logrus.Debugf("Trying to push %s to %s %s", repoInfo.CanonicalName, endpoint.URL, endpoint.Version)
 		logrus.Debugf("Trying to push %s to %s %s", repoInfo.CanonicalName, endpoint.URL, endpoint.Version)
 
 
-		pusher, err := s.NewPusher(endpoint, localRepo, repoInfo, imagePushConfig, sf)
+		pusher, err := s.newPusher(endpoint, localRepo, repoInfo, imagePushConfig, sf)
 		if err != nil {
 		if err != nil {
 			lastErr = err
 			lastErr = err
 			continue
 			continue

+ 3 - 3
graph/push_v1.go

@@ -20,7 +20,7 @@ import (
 type v1Pusher struct {
 type v1Pusher struct {
 	*TagStore
 	*TagStore
 	endpoint  registry.APIEndpoint
 	endpoint  registry.APIEndpoint
-	localRepo Repository
+	localRepo repository
 	repoInfo  *registry.RepositoryInfo
 	repoInfo  *registry.RepositoryInfo
 	config    *ImagePushConfig
 	config    *ImagePushConfig
 	sf        *streamformatter.StreamFormatter
 	sf        *streamformatter.StreamFormatter
@@ -296,7 +296,7 @@ func (p *v1Pusher) pushImage(imgID, ep string) (checksum string, err error) {
 		return "", err
 		return "", err
 	}
 	}
 
 
-	layerData, err := p.graph.TempLayerArchive(imgID, p.sf, p.out)
+	layerData, err := p.graph.tempLayerArchive(imgID, p.sf, p.out)
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("Failed to generate layer archive: %s", err)
 		return "", fmt.Errorf("Failed to generate layer archive: %s", err)
 	}
 	}
@@ -346,7 +346,7 @@ func (p *v1Pusher) getV1ID(id string) (string, error) {
 // getV1Config returns v1Compatibility config for the image in the graph. If
 // getV1Config returns v1Compatibility config for the image in the graph. If
 // there is no v1Compatibility file on disk for the image
 // there is no v1Compatibility file on disk for the image
 func (p *v1Pusher) getV1Config(id string) ([]byte, error) {
 func (p *v1Pusher) getV1Config(id string) ([]byte, error) {
-	jsonData, err := p.graph.GenerateV1CompatibilityChain(id)
+	jsonData, err := p.graph.generateV1CompatibilityChain(id)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 7 - 7
graph/push_v2.go

@@ -27,7 +27,7 @@ const compressionBufSize = 32768
 type v2Pusher struct {
 type v2Pusher struct {
 	*TagStore
 	*TagStore
 	endpoint  registry.APIEndpoint
 	endpoint  registry.APIEndpoint
-	localRepo Repository
+	localRepo repository
 	repoInfo  *registry.RepositoryInfo
 	repoInfo  *registry.RepositoryInfo
 	config    *ImagePushConfig
 	config    *ImagePushConfig
 	sf        *streamformatter.StreamFormatter
 	sf        *streamformatter.StreamFormatter
@@ -40,7 +40,7 @@ type v2Pusher struct {
 }
 }
 
 
 func (p *v2Pusher) Push() (fallback bool, err error) {
 func (p *v2Pusher) Push() (fallback bool, err error) {
-	p.repo, err = NewV2Repository(p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "push", "pull")
+	p.repo, err = newV2Repository(p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "push", "pull")
 	if err != nil {
 	if err != nil {
 		logrus.Debugf("Error getting v2 registry: %v", err)
 		logrus.Debugf("Error getting v2 registry: %v", err)
 		return true, err
 		return true, err
@@ -144,7 +144,7 @@ func (p *v2Pusher) pushV2Tag(tag string) error {
 		}
 		}
 
 
 		var exists bool
 		var exists bool
-		dgst, err := p.graph.GetLayerDigest(layer.ID)
+		dgst, err := p.graph.getLayerDigestWithLock(layer.ID)
 		switch err {
 		switch err {
 		case nil:
 		case nil:
 			if p.layersPushed[dgst] {
 			if p.layersPushed[dgst] {
@@ -165,7 +165,7 @@ func (p *v2Pusher) pushV2Tag(tag string) error {
 				out.Write(p.sf.FormatProgress(stringid.TruncateID(layer.ID), "Image push failed", nil))
 				out.Write(p.sf.FormatProgress(stringid.TruncateID(layer.ID), "Image push failed", nil))
 				return err
 				return err
 			}
 			}
-		case ErrDigestNotSet:
+		case errDigestNotSet:
 			// nop
 			// nop
 		case digest.ErrDigestInvalidFormat, digest.ErrDigestUnsupported:
 		case digest.ErrDigestInvalidFormat, digest.ErrDigestUnsupported:
 			return fmt.Errorf("error getting image checksum: %v", err)
 			return fmt.Errorf("error getting image checksum: %v", err)
@@ -180,7 +180,7 @@ func (p *v2Pusher) pushV2Tag(tag string) error {
 			}
 			}
 			if dgst == "" {
 			if dgst == "" {
 				// Cache new checksum
 				// Cache new checksum
-				if err := p.graph.SetLayerDigest(layer.ID, pushDigest); err != nil {
+				if err := p.graph.setLayerDigestWithLock(layer.ID, pushDigest); err != nil {
 					return err
 					return err
 				}
 				}
 			}
 			}
@@ -188,7 +188,7 @@ func (p *v2Pusher) pushV2Tag(tag string) error {
 		}
 		}
 
 
 		// read v1Compatibility config, generate new if needed
 		// read v1Compatibility config, generate new if needed
-		jsonData, err := p.graph.GenerateV1CompatibilityChain(layer.ID)
+		jsonData, err := p.graph.generateV1CompatibilityChain(layer.ID)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
@@ -230,7 +230,7 @@ func (p *v2Pusher) pushV2Image(bs distribution.BlobService, img *image.Image) (d
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	arch, err := p.graph.TarLayer(image)
+	arch, err := p.graph.tarLayer(image)
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}

+ 4 - 3
graph/registry.go

@@ -7,6 +7,8 @@ import (
 	"net/url"
 	"net/url"
 	"time"
 	"time"
 
 
+	"strings"
+
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
 	"github.com/docker/distribution"
 	"github.com/docker/distribution"
 	"github.com/docker/distribution/digest"
 	"github.com/docker/distribution/digest"
@@ -17,7 +19,6 @@ import (
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
-	"strings"
 )
 )
 
 
 type dumbCredentialStore struct {
 type dumbCredentialStore struct {
@@ -28,10 +29,10 @@ func (dcs dumbCredentialStore) Basic(*url.URL) (string, string) {
 	return dcs.auth.Username, dcs.auth.Password
 	return dcs.auth.Username, dcs.auth.Password
 }
 }
 
 
-// NewV2Repository returns a repository (v2 only). It creates a HTTP transport
+// newV2Repository returns a repository (v2 only). It creates a HTTP transport
 // providing timeout settings and authentication support, and also verifies the
 // providing timeout settings and authentication support, and also verifies the
 // remote API version.
 // remote API version.
-func NewV2Repository(repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint, metaHeaders http.Header, authConfig *cliconfig.AuthConfig, actions ...string) (distribution.Repository, error) {
+func newV2Repository(repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint, metaHeaders http.Header, authConfig *cliconfig.AuthConfig, actions ...string) (distribution.Repository, error) {
 	ctx := context.Background()
 	ctx := context.Background()
 
 
 	repoName := repoInfo.CanonicalName
 	repoName := repoInfo.CanonicalName

+ 4 - 4
graph/service.go

@@ -52,7 +52,7 @@ func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) {
 		Architecture:    image.Architecture,
 		Architecture:    image.Architecture,
 		Os:              image.OS,
 		Os:              image.OS,
 		Size:            image.Size,
 		Size:            image.Size,
-		VirtualSize:     s.graph.GetParentsSize(image) + image.Size,
+		VirtualSize:     s.graph.getParentsSize(image) + image.Size,
 	}
 	}
 
 
 	imageInspect.GraphDriver.Name = s.graph.driver.String()
 	imageInspect.GraphDriver.Name = s.graph.driver.String()
@@ -65,13 +65,13 @@ func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) {
 	return imageInspect, nil
 	return imageInspect, nil
 }
 }
 
 
-// ImageTarLayer return the tarLayer of the image
-func (s *TagStore) ImageTarLayer(name string, dest io.Writer) error {
+// imageTarLayer return the tarLayer of the image
+func (s *TagStore) imageTarLayer(name string, dest io.Writer) error {
 	if image, err := s.LookupImage(name); err == nil && image != nil {
 	if image, err := s.LookupImage(name); err == nil && image != nil {
 		// On Windows, the base layer cannot be exported
 		// On Windows, the base layer cannot be exported
 		if runtime.GOOS != "windows" || image.Parent != "" {
 		if runtime.GOOS != "windows" || image.Parent != "" {
 
 
-			fs, err := s.graph.TarLayer(image)
+			fs, err := s.graph.tarLayer(image)
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}

+ 14 - 16
graph/tags.go

@@ -34,7 +34,7 @@ type TagStore struct {
 	path  string
 	path  string
 	graph *Graph
 	graph *Graph
 	// Repositories is a map of repositories, indexed by name.
 	// Repositories is a map of repositories, indexed by name.
-	Repositories map[string]Repository
+	Repositories map[string]repository
 	trustKey     libtrust.PrivateKey
 	trustKey     libtrust.PrivateKey
 	sync.Mutex
 	sync.Mutex
 	// FIXME: move push/pull-related fields
 	// FIXME: move push/pull-related fields
@@ -45,8 +45,8 @@ type TagStore struct {
 	eventsService   *events.Events
 	eventsService   *events.Events
 }
 }
 
 
-// Repository maps tags to image IDs.
-type Repository map[string]string
+// repository maps tags to image IDs.
+type repository map[string]string
 
 
 // TagStoreConfig provides parameters for a new TagStore.
 // TagStoreConfig provides parameters for a new TagStore.
 type TagStoreConfig struct {
 type TagStoreConfig struct {
@@ -73,7 +73,7 @@ func NewTagStore(path string, cfg *TagStoreConfig) (*TagStore, error) {
 		path:            abspath,
 		path:            abspath,
 		graph:           cfg.Graph,
 		graph:           cfg.Graph,
 		trustKey:        cfg.Key,
 		trustKey:        cfg.Key,
-		Repositories:    make(map[string]Repository),
+		Repositories:    make(map[string]repository),
 		pullingPool:     make(map[string]*broadcaster.Buffered),
 		pullingPool:     make(map[string]*broadcaster.Buffered),
 		pushingPool:     make(map[string]*broadcaster.Buffered),
 		pushingPool:     make(map[string]*broadcaster.Buffered),
 		registryService: cfg.Registry,
 		registryService: cfg.Registry,
@@ -118,8 +118,6 @@ func (store *TagStore) reload() error {
 // name. The name can include an optional tag; otherwise the default tag will
 // name. The name can include an optional tag; otherwise the default tag will
 // be used.
 // be used.
 func (store *TagStore) LookupImage(name string) (*image.Image, error) {
 func (store *TagStore) LookupImage(name string) (*image.Image, error) {
-	// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
-	// (so we can pass all errors here)
 	repoName, ref := parsers.ParseRepositoryTag(name)
 	repoName, ref := parsers.ParseRepositoryTag(name)
 	if ref == "" {
 	if ref == "" {
 		ref = tags.DefaultTag
 		ref = tags.DefaultTag
@@ -129,7 +127,7 @@ func (store *TagStore) LookupImage(name string) (*image.Image, error) {
 		img *image.Image
 		img *image.Image
 	)
 	)
 
 
-	img, err = store.GetImage(repoName, ref)
+	img, err = store.getImage(repoName, ref)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -257,7 +255,7 @@ func (store *TagStore) setLoad(repoName, tag, imageName string, force bool, out
 	if err := store.reload(); err != nil {
 	if err := store.reload(); err != nil {
 		return err
 		return err
 	}
 	}
-	var repo Repository
+	var repo repository
 	repoName = registry.NormalizeLocalName(repoName)
 	repoName = registry.NormalizeLocalName(repoName)
 	if r, exists := store.Repositories[repoName]; exists {
 	if r, exists := store.Repositories[repoName]; exists {
 		repo = r
 		repo = r
@@ -281,8 +279,8 @@ func (store *TagStore) setLoad(repoName, tag, imageName string, force bool, out
 	return store.save()
 	return store.save()
 }
 }
 
 
-// SetDigest creates a digest reference to an image ID.
-func (store *TagStore) SetDigest(repoName, digest, imageName string) error {
+// setDigest creates a digest reference to an image ID.
+func (store *TagStore) setDigest(repoName, digest, imageName string) error {
 	img, err := store.LookupImage(imageName)
 	img, err := store.LookupImage(imageName)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
@@ -305,7 +303,7 @@ func (store *TagStore) SetDigest(repoName, digest, imageName string) error {
 	repoName = registry.NormalizeLocalName(repoName)
 	repoName = registry.NormalizeLocalName(repoName)
 	repoRefs, exists := store.Repositories[repoName]
 	repoRefs, exists := store.Repositories[repoName]
 	if !exists {
 	if !exists {
-		repoRefs = Repository{}
+		repoRefs = repository{}
 		store.Repositories[repoName] = repoRefs
 		store.Repositories[repoName] = repoRefs
 	} else if oldID, exists := repoRefs[digest]; exists && oldID != img.ID {
 	} else if oldID, exists := repoRefs[digest]; exists && oldID != img.ID {
 		return fmt.Errorf("Conflict: Digest %s is already set to image %s", digest, oldID)
 		return fmt.Errorf("Conflict: Digest %s is already set to image %s", digest, oldID)
@@ -315,8 +313,8 @@ func (store *TagStore) SetDigest(repoName, digest, imageName string) error {
 	return store.save()
 	return store.save()
 }
 }
 
 
-// Get returns the Repository tag/image map for a given repository.
-func (store *TagStore) Get(repoName string) (Repository, error) {
+// get returns the repository tag/image map for a given repository.
+func (store *TagStore) get(repoName string) (repository, error) {
 	store.Lock()
 	store.Lock()
 	defer store.Unlock()
 	defer store.Unlock()
 	if err := store.reload(); err != nil {
 	if err := store.reload(); err != nil {
@@ -329,10 +327,10 @@ func (store *TagStore) Get(repoName string) (Repository, error) {
 	return nil, nil
 	return nil, nil
 }
 }
 
 
-// GetImage returns a pointer to an Image structure describing the image
+// getImage returns a pointer to an Image structure describing the image
 // referred to by refOrID inside repository repoName.
 // referred to by refOrID inside repository repoName.
-func (store *TagStore) GetImage(repoName, refOrID string) (*image.Image, error) {
-	repo, err := store.Get(repoName)
+func (store *TagStore) getImage(repoName, refOrID string) (*image.Image, error) {
+	repo, err := store.get(repoName)
 
 
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err

+ 1 - 1
graph/tags_unit_test.go

@@ -92,7 +92,7 @@ func mkTestTagStore(root string, t *testing.T) *TagStore {
 	if err := store.Tag(testPrivateImageName, "", testPrivateImageID, false); err != nil {
 	if err := store.Tag(testPrivateImageName, "", testPrivateImageID, false); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
-	if err := store.SetDigest(testPrivateImageName, testPrivateImageDigest, testPrivateImageID); err != nil {
+	if err := store.setDigest(testPrivateImageName, testPrivateImageDigest, testPrivateImageID); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 	return store
 	return store