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

continue daemon refactor of Repositories()

- use daemon member directly rather than through a function call
 - create GetImage method for use external to deamon

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
This commit is contained in:
Morgan Bauer 2015-10-01 14:51:36 -07:00
parent b50a88cfd7
commit ee36b57c8f
No known key found for this signature in database
GPG key ID: 23F15C502128F348
5 changed files with 20 additions and 18 deletions

View file

@ -425,7 +425,7 @@ func (s *router) postBuild(ctx context.Context, w http.ResponseWriter, r *http.R
}
if repoName != "" {
if err := s.daemon.Repositories().Tag(repoName, tag, string(imgID), true); err != nil {
if err := s.daemon.TagImage(repoName, tag, string(imgID), true); err != nil {
return errf(err)
}
}

View file

@ -1011,11 +1011,6 @@ func (daemon *Daemon) Graph() *graph.Graph {
return daemon.graph
}
// Repositories returns all repositories.
func (daemon *Daemon) Repositories() *graph.TagStore {
return daemon.repositories
}
// TagImage creates a tag in the repository reponame, pointing to the image named
// imageName. If force is true, an existing tag with the same name may be
// overwritten.
@ -1079,6 +1074,13 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
return daemon.repositories.History(name)
}
// GetImage returns pointer to an Image struct corresponding to the given
// name. The name can include an optional tag; otherwise the default tag will
// be used.
func (daemon *Daemon) GetImage(name string) (*image.Image, error) {
return daemon.repositories.LookupImage(name)
}
func (daemon *Daemon) config() *Config {
return daemon.configStore
}

View file

@ -39,7 +39,7 @@ var _ builder.Docker = Docker{}
// LookupImage looks up a Docker image referenced by `name`.
func (d Docker) LookupImage(name string) (*image.Image, error) {
return d.Daemon.Repositories().LookupImage(name)
return d.Daemon.GetImage(name)
}
// Pull tells Docker to pull image referenced by `name`.
@ -69,11 +69,11 @@ func (d Docker) Pull(name string) (*image.Image, error) {
OutStream: ioutils.NopWriteCloser(d.OutOld),
}
if err := d.Daemon.Repositories().Pull(remote, tag, imagePullConfig); err != nil {
if err := d.Daemon.PullImage(remote, tag, imagePullConfig); err != nil {
return nil, err
}
return d.Daemon.Repositories().LookupImage(name)
return d.Daemon.GetImage(name)
}
// Container looks up a Docker container referenced by `id`.

View file

@ -53,7 +53,7 @@ import (
func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) {
records := []types.ImageDelete{}
img, err := daemon.Repositories().LookupImage(imageRef)
img, err := daemon.repositories.LookupImage(imageRef)
if err != nil {
return nil, err
}
@ -90,7 +90,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
// repository reference to the image then we will want to
// remove that reference.
// FIXME: Is this the behavior we want?
repoRefs := daemon.Repositories().ByID()[img.ID]
repoRefs := daemon.repositories.ByID()[img.ID]
if len(repoRefs) == 1 {
parsedRef, err := daemon.removeImageRef(repoRefs[0])
if err != nil {
@ -116,7 +116,7 @@ func isImageIDPrefix(imageID, possiblePrefix string) bool {
// imageHasMultipleRepositoryReferences returns whether there are multiple
// repository references to the given imageID.
func (daemon *Daemon) imageHasMultipleRepositoryReferences(imageID string) bool {
return len(daemon.Repositories().ByID()[imageID]) > 1
return len(daemon.repositories.ByID()[imageID]) > 1
}
// getContainerUsingImage returns a container that was created using the given
@ -145,7 +145,7 @@ func (daemon *Daemon) removeImageRef(repositoryRef string) (string, error) {
// Ignore the boolean value returned, as far as we're concerned, this
// is an idempotent operation and it's okay if the reference didn't
// exist in the first place.
_, err := daemon.Repositories().Delete(repository, ref)
_, err := daemon.repositories.Delete(repository, ref)
return utils.ImageReference(repository, ref), err
}
@ -156,7 +156,7 @@ func (daemon *Daemon) removeImageRef(repositoryRef string) (string, error) {
// daemon's event service. An "Untagged" types.ImageDelete is added to the
// given list of records.
func (daemon *Daemon) removeAllReferencesToImageID(imgID string, records *[]types.ImageDelete) error {
imageRefs := daemon.Repositories().ByID()[imgID]
imageRefs := daemon.repositories.ByID()[imgID]
for _, imageRef := range imageRefs {
parsedRef, err := daemon.removeImageRef(imageRef)
@ -308,7 +308,7 @@ func (daemon *Daemon) checkImageDeleteHardConflict(img *image.Image) *imageDelet
func (daemon *Daemon) checkImageDeleteSoftConflict(img *image.Image) *imageDeleteConflict {
// Check if any repository tags/digest reference this image.
if daemon.Repositories().HasReferences(img) {
if daemon.repositories.HasReferences(img) {
return &imageDeleteConflict{
imgID: img.ID,
message: "image is referenced in one or more repositories",
@ -337,5 +337,5 @@ func (daemon *Daemon) checkImageDeleteSoftConflict(img *image.Image) *imageDelet
// that there are no repository references to the given image and it has no
// child images.
func (daemon *Daemon) imageIsDangling(img *image.Image) bool {
return !(daemon.Repositories().HasReferences(img) || daemon.Graph().HasChildren(img))
return !(daemon.repositories.HasReferences(img) || daemon.Graph().HasChildren(img))
}

View file

@ -163,7 +163,7 @@ func (daemon *Daemon) foldFilter(config *ContainersConfig) (*listContext, error)
// The idea is to walk the graph down the most "efficient" way.
for _, ancestor := range ancestors {
// First, get the imageId of the ancestor filter (yay)
image, err := daemon.Repositories().LookupImage(ancestor)
image, err := daemon.repositories.LookupImage(ancestor)
if err != nil {
logrus.Warnf("Error while looking up for image %v", ancestor)
continue
@ -297,7 +297,7 @@ func (daemon *Daemon) transformContainer(container *Container, ctx *listContext)
newC.Names = []string{}
}
img, err := daemon.Repositories().LookupImage(container.Config.Image)
img, err := daemon.repositories.LookupImage(container.Config.Image)
if err != nil {
// If the image can no longer be found by its original reference,
// it makes sense to show the ID instead of a stale reference.