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

Store the checksums when pulling a repository

This commit is contained in:
Guillaume J. Charmes 2013-05-08 16:22:12 -07:00
parent 6cafed45af
commit 0e23b4e10e
3 changed files with 48 additions and 10 deletions

View file

@ -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{

View file

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

View file

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