2014-03-08 02:04:38 +00:00
|
|
|
package graph
|
2013-03-21 19:18:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-02-27 02:23:50 +00:00
|
|
|
"errors"
|
2013-03-22 03:06:20 +00:00
|
|
|
"fmt"
|
2015-04-01 14:44:40 +00:00
|
|
|
"io"
|
2013-03-21 19:18:47 +00:00
|
|
|
"io/ioutil"
|
2013-03-22 02:00:43 +00:00
|
|
|
"os"
|
2013-03-21 19:18:47 +00:00
|
|
|
"path/filepath"
|
2014-09-11 14:32:44 +00:00
|
|
|
"regexp"
|
2013-03-26 22:30:16 +00:00
|
|
|
"sort"
|
2013-03-22 03:06:20 +00:00
|
|
|
"strings"
|
2014-05-29 12:22:13 +00:00
|
|
|
"sync"
|
|
|
|
|
2015-04-03 22:17:49 +00:00
|
|
|
"github.com/docker/docker/daemon/events"
|
2014-07-24 22:19:50 +00:00
|
|
|
"github.com/docker/docker/image"
|
2014-07-29 00:23:38 +00:00
|
|
|
"github.com/docker/docker/pkg/parsers"
|
2015-03-24 11:25:26 +00:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2014-10-07 01:54:52 +00:00
|
|
|
"github.com/docker/docker/registry"
|
2015-02-27 02:23:50 +00:00
|
|
|
"github.com/docker/docker/utils"
|
2015-01-07 22:59:12 +00:00
|
|
|
"github.com/docker/libtrust"
|
2013-03-21 19:18:47 +00:00
|
|
|
)
|
|
|
|
|
2013-06-04 18:00:22 +00:00
|
|
|
const DEFAULTTAG = "latest"
|
2013-03-22 23:07:13 +00:00
|
|
|
|
2014-09-11 14:32:44 +00:00
|
|
|
var (
|
2015-02-27 02:23:50 +00:00
|
|
|
//FIXME these 2 regexes also exist in registry/v2/regexp.go
|
2014-10-07 15:13:17 +00:00
|
|
|
validTagName = regexp.MustCompile(`^[\w][\w.-]{0,127}$`)
|
2015-02-27 02:23:50 +00:00
|
|
|
validDigest = regexp.MustCompile(`[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+`)
|
2014-09-11 14:32:44 +00:00
|
|
|
)
|
|
|
|
|
2013-03-22 00:35:49 +00:00
|
|
|
type TagStore struct {
|
2014-10-07 01:54:52 +00:00
|
|
|
path string
|
|
|
|
graph *Graph
|
|
|
|
Repositories map[string]Repository
|
2015-01-07 22:59:12 +00:00
|
|
|
trustKey libtrust.PrivateKey
|
2014-05-29 12:22:13 +00:00
|
|
|
sync.Mutex
|
2014-08-08 06:58:58 +00:00
|
|
|
// FIXME: move push/pull-related fields
|
|
|
|
// to a helper type
|
2015-03-31 23:21:37 +00:00
|
|
|
pullingPool map[string]chan struct{}
|
|
|
|
pushingPool map[string]chan struct{}
|
|
|
|
registryService *registry.Service
|
2015-04-03 22:17:49 +00:00
|
|
|
eventsService *events.Events
|
2013-03-21 19:18:47 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 00:35:49 +00:00
|
|
|
type Repository map[string]string
|
2013-03-21 19:18:47 +00:00
|
|
|
|
2014-05-01 04:26:24 +00:00
|
|
|
// update Repository mapping with content of u
|
|
|
|
func (r Repository) Update(u Repository) {
|
|
|
|
for k, v := range u {
|
|
|
|
r[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the contents of u Repository, are wholly contained in r Repository
|
|
|
|
func (r Repository) Contains(u Repository) bool {
|
|
|
|
for k, v := range u {
|
|
|
|
// if u's key is not present in r OR u's key is present, but not the same value
|
|
|
|
if rv, ok := r[k]; !ok || (ok && rv != v) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-04-03 22:17:49 +00:00
|
|
|
func NewTagStore(path string, graph *Graph, key libtrust.PrivateKey, registryService *registry.Service, eventsService *events.Events) (*TagStore, error) {
|
2013-03-21 19:18:47 +00:00
|
|
|
abspath, err := filepath.Abs(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-08-19 18:54:42 +00:00
|
|
|
|
2013-03-22 00:35:49 +00:00
|
|
|
store := &TagStore{
|
2015-03-31 23:21:37 +00:00
|
|
|
path: abspath,
|
|
|
|
graph: graph,
|
|
|
|
trustKey: key,
|
|
|
|
Repositories: make(map[string]Repository),
|
|
|
|
pullingPool: make(map[string]chan struct{}),
|
|
|
|
pushingPool: make(map[string]chan struct{}),
|
|
|
|
registryService: registryService,
|
2015-04-03 22:17:49 +00:00
|
|
|
eventsService: eventsService,
|
2013-03-21 19:18:47 +00:00
|
|
|
}
|
2013-03-22 02:00:43 +00:00
|
|
|
// Load the json file if it exists, otherwise create it.
|
2014-05-29 12:22:13 +00:00
|
|
|
if err := store.reload(); os.IsNotExist(err) {
|
|
|
|
if err := store.save(); err != nil {
|
2013-03-22 02:00:43 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else if err != nil {
|
2013-03-21 19:18:47 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return store, nil
|
|
|
|
}
|
|
|
|
|
2014-05-29 12:22:13 +00:00
|
|
|
func (store *TagStore) save() error {
|
2013-03-21 19:18:47 +00:00
|
|
|
// Store the json ball
|
|
|
|
jsonData, err := json.Marshal(store)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := ioutil.WriteFile(store.path, jsonData, 0600); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-05-29 12:22:13 +00:00
|
|
|
func (store *TagStore) reload() error {
|
2013-03-21 19:18:47 +00:00
|
|
|
jsonData, err := ioutil.ReadFile(store.path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal(jsonData, store); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:36:47 +00:00
|
|
|
func (store *TagStore) LookupImage(name string) (*image.Image, error) {
|
2013-11-29 19:06:35 +00:00
|
|
|
// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
|
|
|
|
// (so we can pass all errors here)
|
2015-02-27 02:23:50 +00:00
|
|
|
repoName, ref := parsers.ParseRepositoryTag(name)
|
|
|
|
if ref == "" {
|
|
|
|
ref = DEFAULTTAG
|
|
|
|
}
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
img *image.Image
|
|
|
|
)
|
|
|
|
|
|
|
|
img, err = store.GetImage(repoName, ref)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if img != nil {
|
|
|
|
return img, err
|
2013-11-29 19:06:35 +00:00
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
|
|
|
// name must be an image ID.
|
2014-05-29 12:22:13 +00:00
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
2015-02-27 02:23:50 +00:00
|
|
|
if img, err = store.graph.Get(name); err != nil {
|
2013-11-29 19:06:35 +00:00
|
|
|
return nil, err
|
2013-03-22 23:07:13 +00:00
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
2013-03-22 23:07:13 +00:00
|
|
|
return img, nil
|
|
|
|
}
|
|
|
|
|
2013-03-23 02:22:06 +00:00
|
|
|
// Return a reverse-lookup table of all the names which refer to each image
|
|
|
|
// Eg. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
2013-06-04 18:00:22 +00:00
|
|
|
func (store *TagStore) ByID() map[string][]string {
|
2014-05-29 12:22:13 +00:00
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
2013-06-04 18:00:22 +00:00
|
|
|
byID := make(map[string][]string)
|
2013-03-23 02:22:06 +00:00
|
|
|
for repoName, repository := range store.Repositories {
|
|
|
|
for tag, id := range repository {
|
2015-02-27 02:23:50 +00:00
|
|
|
name := utils.ImageReference(repoName, tag)
|
2013-06-04 18:00:22 +00:00
|
|
|
if _, exists := byID[id]; !exists {
|
|
|
|
byID[id] = []string{name}
|
2013-03-23 02:22:06 +00:00
|
|
|
} else {
|
2013-06-04 18:00:22 +00:00
|
|
|
byID[id] = append(byID[id], name)
|
|
|
|
sort.Strings(byID[id])
|
2013-03-23 02:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-04 18:00:22 +00:00
|
|
|
return byID
|
2013-03-23 02:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (store *TagStore) ImageName(id string) string {
|
2013-06-04 18:00:22 +00:00
|
|
|
if names, exists := store.ByID()[id]; exists && len(names) > 0 {
|
2013-03-23 02:22:06 +00:00
|
|
|
return names[0]
|
|
|
|
}
|
2015-03-24 11:25:26 +00:00
|
|
|
return stringid.TruncateID(id)
|
2013-03-23 02:22:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 22:53:45 +00:00
|
|
|
func (store *TagStore) DeleteAll(id string) error {
|
2013-06-10 21:05:54 +00:00
|
|
|
names, exists := store.ByID()[id]
|
2013-05-30 22:53:45 +00:00
|
|
|
if !exists || len(names) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
for _, name := range names {
|
|
|
|
if strings.Contains(name, ":") {
|
|
|
|
nameParts := strings.Split(name, ":")
|
2013-05-31 14:37:02 +00:00
|
|
|
if _, err := store.Delete(nameParts[0], nameParts[1]); err != nil {
|
2013-05-30 22:53:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2013-05-31 14:37:02 +00:00
|
|
|
if _, err := store.Delete(name, ""); err != nil {
|
2013-05-30 22:53:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-27 02:23:50 +00:00
|
|
|
func (store *TagStore) Delete(repoName, ref string) (bool, error) {
|
2014-05-29 12:22:13 +00:00
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
2013-05-31 14:37:02 +00:00
|
|
|
deleted := false
|
2014-05-29 12:22:13 +00:00
|
|
|
if err := store.reload(); err != nil {
|
2013-05-31 14:37:02 +00:00
|
|
|
return false, err
|
2013-05-15 13:11:39 +00:00
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
2014-10-07 01:54:52 +00:00
|
|
|
repoName = registry.NormalizeLocalName(repoName)
|
2015-02-27 02:23:50 +00:00
|
|
|
|
|
|
|
if ref == "" {
|
|
|
|
// Delete the whole repository.
|
|
|
|
delete(store.Repositories, repoName)
|
|
|
|
return true, store.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
repoRefs, exists := store.Repositories[repoName]
|
|
|
|
if !exists {
|
|
|
|
return false, fmt.Errorf("No such repository: %s", repoName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, exists := repoRefs[ref]; exists {
|
|
|
|
delete(repoRefs, ref)
|
|
|
|
if len(repoRefs) == 0 {
|
2013-05-15 13:11:39 +00:00
|
|
|
delete(store.Repositories, repoName)
|
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
deleted = true
|
2013-05-15 13:11:39 +00:00
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
2014-05-29 12:22:13 +00:00
|
|
|
return deleted, store.save()
|
2013-03-23 02:22:06 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 01:27:18 +00:00
|
|
|
func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
2015-04-01 14:44:40 +00:00
|
|
|
return store.SetLoad(repoName, tag, imageName, force, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *TagStore) SetLoad(repoName, tag, imageName string, force bool, out io.Writer) error {
|
2013-03-23 01:27:18 +00:00
|
|
|
img, err := store.LookupImage(imageName)
|
2014-05-29 12:22:13 +00:00
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
2013-03-23 01:27:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-03-22 23:07:13 +00:00
|
|
|
if tag == "" {
|
2013-06-04 18:00:22 +00:00
|
|
|
tag = DEFAULTTAG
|
2013-03-22 03:06:20 +00:00
|
|
|
}
|
2013-03-22 23:07:13 +00:00
|
|
|
if err := validateRepoName(repoName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-09-29 09:52:13 +00:00
|
|
|
if err := ValidateTagName(tag); err != nil {
|
2013-03-22 23:07:13 +00:00
|
|
|
return err
|
2013-03-22 03:06:20 +00:00
|
|
|
}
|
2014-05-29 12:22:13 +00:00
|
|
|
if err := store.reload(); err != nil {
|
2013-03-21 19:18:47 +00:00
|
|
|
return err
|
|
|
|
}
|
2013-03-22 00:35:49 +00:00
|
|
|
var repo Repository
|
2014-10-07 01:54:52 +00:00
|
|
|
repoName = registry.NormalizeLocalName(repoName)
|
2013-03-21 19:18:47 +00:00
|
|
|
if r, exists := store.Repositories[repoName]; exists {
|
|
|
|
repo = r
|
2015-04-01 14:44:40 +00:00
|
|
|
if old, exists := store.Repositories[repoName][tag]; exists {
|
|
|
|
|
|
|
|
if !force {
|
|
|
|
return fmt.Errorf("Conflict: Tag %s is already set to image %s, if you want to replace it, please use -f option", tag, old)
|
|
|
|
}
|
|
|
|
|
|
|
|
if old != img.ID && out != nil {
|
|
|
|
|
|
|
|
fmt.Fprintf(out, "The image %s:%s already exists, renaming the old one with ID %s to empty string\n", repoName, tag, old[:12])
|
|
|
|
|
|
|
|
}
|
2014-09-30 08:57:17 +00:00
|
|
|
}
|
2013-03-21 19:18:47 +00:00
|
|
|
} else {
|
2013-03-22 00:35:49 +00:00
|
|
|
repo = make(map[string]string)
|
2013-03-21 19:18:47 +00:00
|
|
|
store.Repositories[repoName] = repo
|
|
|
|
}
|
2013-06-04 18:00:22 +00:00
|
|
|
repo[tag] = img.ID
|
2014-05-29 12:22:13 +00:00
|
|
|
return store.save()
|
2013-03-21 19:18:47 +00:00
|
|
|
}
|
|
|
|
|
2015-02-27 02:23:50 +00:00
|
|
|
// SetDigest creates a digest reference to an image ID.
|
|
|
|
func (store *TagStore) SetDigest(repoName, digest, imageName string) error {
|
|
|
|
img, err := store.LookupImage(imageName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validateRepoName(repoName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validateDigest(digest); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
|
|
|
if err := store.reload(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
repoName = registry.NormalizeLocalName(repoName)
|
|
|
|
repoRefs, exists := store.Repositories[repoName]
|
|
|
|
if !exists {
|
|
|
|
repoRefs = Repository{}
|
|
|
|
store.Repositories[repoName] = repoRefs
|
|
|
|
} else if oldID, exists := repoRefs[digest]; exists && oldID != img.ID {
|
|
|
|
return fmt.Errorf("Conflict: Digest %s is already set to image %s", digest, oldID)
|
|
|
|
}
|
|
|
|
|
|
|
|
repoRefs[digest] = img.ID
|
|
|
|
return store.save()
|
|
|
|
}
|
|
|
|
|
2013-03-22 00:35:49 +00:00
|
|
|
func (store *TagStore) Get(repoName string) (Repository, error) {
|
2014-05-29 12:22:13 +00:00
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
|
|
|
if err := store.reload(); err != nil {
|
2013-03-21 19:18:47 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2014-10-07 01:54:52 +00:00
|
|
|
repoName = registry.NormalizeLocalName(repoName)
|
2013-03-21 19:18:47 +00:00
|
|
|
if r, exists := store.Repositories[repoName]; exists {
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-02-27 02:23:50 +00:00
|
|
|
func (store *TagStore) GetImage(repoName, refOrID string) (*image.Image, error) {
|
2013-03-21 19:18:47 +00:00
|
|
|
repo, err := store.Get(repoName)
|
2015-02-27 02:23:50 +00:00
|
|
|
|
2013-03-21 19:18:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-02-27 02:23:50 +00:00
|
|
|
}
|
|
|
|
if repo == nil {
|
2013-03-21 19:18:47 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
|
|
|
if imgID, exists := repo[refOrID]; exists {
|
|
|
|
return store.graph.Get(imgID)
|
2013-06-28 16:06:00 +00:00
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
2013-06-28 16:06:00 +00:00
|
|
|
// If no matching tag is found, search through images for a matching image id
|
2013-06-03 20:00:15 +00:00
|
|
|
for _, revision := range repo {
|
2015-02-27 02:23:50 +00:00
|
|
|
if strings.HasPrefix(revision, refOrID) {
|
2013-06-03 20:00:15 +00:00
|
|
|
return store.graph.Get(revision)
|
|
|
|
}
|
|
|
|
}
|
2015-02-27 02:23:50 +00:00
|
|
|
|
2013-03-21 19:18:47 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
2013-03-22 23:07:13 +00:00
|
|
|
|
2014-05-29 12:22:13 +00:00
|
|
|
func (store *TagStore) GetRepoRefs() map[string][]string {
|
|
|
|
store.Lock()
|
|
|
|
reporefs := make(map[string][]string)
|
|
|
|
|
|
|
|
for name, repository := range store.Repositories {
|
|
|
|
for tag, id := range repository {
|
2015-03-24 11:25:26 +00:00
|
|
|
shortID := stringid.TruncateID(id)
|
2015-02-27 02:23:50 +00:00
|
|
|
reporefs[shortID] = append(reporefs[shortID], utils.ImageReference(name, tag))
|
2014-05-29 12:22:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
store.Unlock()
|
|
|
|
return reporefs
|
|
|
|
}
|
|
|
|
|
2013-03-22 23:07:13 +00:00
|
|
|
// Validate the name of a repository
|
|
|
|
func validateRepoName(name string) error {
|
|
|
|
if name == "" {
|
|
|
|
return fmt.Errorf("Repository name can't be empty")
|
|
|
|
}
|
2014-10-28 21:06:23 +00:00
|
|
|
if name == "scratch" {
|
|
|
|
return fmt.Errorf("'scratch' is a reserved name")
|
|
|
|
}
|
2013-03-22 23:07:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-27 02:23:50 +00:00
|
|
|
// ValidateTagName validates the name of a tag
|
2014-09-29 09:52:13 +00:00
|
|
|
func ValidateTagName(name string) error {
|
2013-03-22 23:07:13 +00:00
|
|
|
if name == "" {
|
2015-02-27 02:23:50 +00:00
|
|
|
return fmt.Errorf("tag name can't be empty")
|
2013-03-22 23:07:13 +00:00
|
|
|
}
|
2014-09-11 14:32:44 +00:00
|
|
|
if !validTagName.MatchString(name) {
|
2014-12-19 22:48:31 +00:00
|
|
|
return fmt.Errorf("Illegal tag name (%s): only [A-Za-z0-9_.-] are allowed, minimum 1, maximum 128 in length", name)
|
2013-03-22 23:07:13 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2014-08-08 06:58:58 +00:00
|
|
|
|
2015-02-27 02:23:50 +00:00
|
|
|
func validateDigest(dgst string) error {
|
|
|
|
if dgst == "" {
|
|
|
|
return errors.New("digest can't be empty")
|
|
|
|
}
|
|
|
|
if !validDigest.MatchString(dgst) {
|
|
|
|
return fmt.Errorf("illegal digest (%s): must be of the form [a-zA-Z0-9-_+.]+:[a-fA-F0-9]+", dgst)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-08-29 11:21:28 +00:00
|
|
|
func (store *TagStore) poolAdd(kind, key string) (chan struct{}, error) {
|
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
2014-08-08 06:58:58 +00:00
|
|
|
|
2014-08-29 11:21:28 +00:00
|
|
|
if c, exists := store.pullingPool[key]; exists {
|
2014-08-08 06:58:58 +00:00
|
|
|
return c, fmt.Errorf("pull %s is already in progress", key)
|
|
|
|
}
|
2014-08-29 11:21:28 +00:00
|
|
|
if c, exists := store.pushingPool[key]; exists {
|
2014-08-08 06:58:58 +00:00
|
|
|
return c, fmt.Errorf("push %s is already in progress", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
c := make(chan struct{})
|
|
|
|
switch kind {
|
|
|
|
case "pull":
|
2014-08-29 11:21:28 +00:00
|
|
|
store.pullingPool[key] = c
|
2014-08-08 06:58:58 +00:00
|
|
|
case "push":
|
2014-08-29 11:21:28 +00:00
|
|
|
store.pushingPool[key] = c
|
2014-08-08 06:58:58 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("Unknown pool type")
|
|
|
|
}
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2014-08-29 11:21:28 +00:00
|
|
|
func (store *TagStore) poolRemove(kind, key string) error {
|
|
|
|
store.Lock()
|
|
|
|
defer store.Unlock()
|
2014-08-08 06:58:58 +00:00
|
|
|
switch kind {
|
|
|
|
case "pull":
|
2014-08-29 11:21:28 +00:00
|
|
|
if c, exists := store.pullingPool[key]; exists {
|
2014-08-08 06:58:58 +00:00
|
|
|
close(c)
|
2014-08-29 11:21:28 +00:00
|
|
|
delete(store.pullingPool, key)
|
2014-08-08 06:58:58 +00:00
|
|
|
}
|
|
|
|
case "push":
|
2014-08-29 11:21:28 +00:00
|
|
|
if c, exists := store.pushingPool[key]; exists {
|
2014-08-08 06:58:58 +00:00
|
|
|
close(c)
|
2014-08-29 11:21:28 +00:00
|
|
|
delete(store.pushingPool, key)
|
2014-08-08 06:58:58 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("Unknown pool type")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|