diff --git a/graph.go b/graph.go index 4b504525e7..84b8c9a1e9 100644 --- a/graph.go +++ b/graph.go @@ -31,7 +31,7 @@ func NewGraph(root string) (*Graph, error) { return nil, err } // Create the root directory if it doesn't exists - if err := os.Mkdir(root, 0700); err != nil && !os.IsExist(err) { + if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(err) { return nil, err } graph := &Graph{ diff --git a/image.go b/image.go index 3e8ac55d3d..d208ed6ce8 100644 --- a/image.go +++ b/image.go @@ -303,16 +303,12 @@ func (img *Image) Checksum() (string, error) { return "", err } - fmt.Printf("precopy %s: %s\n", img.ShortId(), time.Now().String()) - if _, err := io.Copy(h, layerData); err != nil { return "", err } - fmt.Printf("postcopy presum %s: %s\n", img.ShortId(), time.Now().String()) hash := "sha256:" + hex.EncodeToString(h.Sum(nil)) checksums[img.Id] = hash - fmt.Printf("postsum %s: %s\n", img.ShortId(), time.Now().String()) // Reload the json file to make sure not to overwrite faster sums img.graph.lockSumFile.Lock() diff --git a/registry.go b/registry.go index 07268313a3..bf6556f6d5 100644 --- a/registry.go +++ b/registry.go @@ -194,18 +194,16 @@ func (graph *Graph) getRemoteTags(stdout io.Writer, registries []string, reposit return nil, fmt.Errorf("Repository not found") } - result := new(map[string]string) + result := make(map[string]string) rawJson, err := ioutil.ReadAll(res.Body) if err != nil { return nil, err } - if err = json.Unmarshal(rawJson, result); err != nil { + if err = json.Unmarshal(rawJson, &result); err != nil { return nil, err } - - return *result, nil - + return result, nil } return nil, fmt.Errorf("Could not reach any registry endpoint") } @@ -308,6 +306,50 @@ func (graph *Graph) PullRepository(stdout io.Writer, remote, askedTag string, re return fmt.Errorf("Index response didn't contain any endpoints") } + checksumsJson, err := ioutil.ReadAll(res.Body) + if err != nil { + return err + } + + // Reload the json file to make sure not to overwrite faster sums + err = func() error { + localChecksums := make(map[string]string) + remoteChecksums := []struct { + Id string `json: "id"` + Checksum string `json: "checksum"` + }{} + checksumDictPth := path.Join(graph.Root, "..", "checksums") + + if err := json.Unmarshal(checksumsJson, &remoteChecksums); err != nil { + return err + } + + graph.lockSumFile.Lock() + defer graph.lockSumFile.Unlock() + + if checksumDict, err := ioutil.ReadFile(checksumDictPth); err == nil { + if err := json.Unmarshal(checksumDict, &localChecksums); err != nil { + return err + } + } + + for _, elem := range remoteChecksums { + localChecksums[elem.Id] = elem.Checksum + } + + checksumsJson, err = json.Marshal(localChecksums) + if err != nil { + return err + } + if err := ioutil.WriteFile(checksumDictPth, checksumsJson, 0600); err != nil { + return err + } + return nil + }() + if err != nil { + return err + } + var tagsList map[string]string if askedTag == "" { tagsList, err = graph.getRemoteTags(stdout, endpoints, remote, token)