func StoreChecksum(s storage.Storage, imageID string, checksums []string) error { for _, checksum := range checksums { parts := strings.Split(checksum, ":") if len(parts) != 2 { return errors.New("Invalid checksum format") } } content, err := json.Marshal(checksums) if err != nil { return err } return s.Put(storage.ImageChecksumPath(imageID), content) }
func GenerateAncestry(s storage.Storage, imageID, parentID string) (err error) { logger.Debug("[GenerateAncestry] imageID=" + imageID + " parentID=" + parentID) path := storage.ImageAncestryPath(imageID) if parentID == "" { return s.Put(path, []byte(`["`+imageID+`"]`)) } var content []byte if content, err = s.Get(storage.ImageAncestryPath(parentID)); err != nil { return err } var ancestry []string if err := json.Unmarshal(content, &ancestry); err != nil { return err } ancestry = append([]string{imageID}, ancestry...) if content, err = json.Marshal(&ancestry); err != nil { return err } return s.Put(path, content) }
// this function takes both []byte and []map[string]interface{} to shortcut in some cases. func UpdateIndexImages(s storage.Storage, namespace, repo string, additionalBytes []byte, additional []map[string]interface{}) error { path := storage.RepoIndexImagesPath(namespace, repo) // get previous content previousData, err := s.Get(path) if err != nil { // doesn't yet exist, just put the data return s.Put(path, additionalBytes) } var previous []map[string]interface{} if err := json.Unmarshal(previousData, &previous); err != nil { return err } if len(previous) == 0 { // nothing in previous, just put the data return s.Put(path, additionalBytes) } // Merge existing images with the incoming images. if the image ID exists in the existing, check to see if // the checksum is the same. if it is just continue, if it isn't replace it with the incoming image newImagesMap := map[string]map[string]interface{}{} for _, value := range additional { id, ok := value["id"].(string) if !ok { // json was screwed up return errors.New("Invalid Data") } if imageData, ok := newImagesMap[id]; ok { if _, ok := imageData["checksum"]; ok { continue } } newImagesMap[id] = value } for _, value := range previous { id, ok := value["id"].(string) if !ok { // json was screwed up return errors.New("Invalid Data") } if imageData, ok := newImagesMap[id]; ok { if _, ok := imageData["checksum"]; ok { continue } } newImagesMap[id] = value } newImagesArr := make([]map[string]interface{}, len(newImagesMap)) i := 0 for _, image := range newImagesMap { newImagesArr[i] = image i++ } data, err := json.Marshal(&newImagesArr) if err != nil { return err } return s.Put(path, data) }
func SetImageFilesCache(s storage.Storage, imageID string, filesJson []byte) error { return s.Put(storage.ImageFilesPath(imageID), filesJson) }
func SetImageDiffCache(s storage.Storage, imageID string, diffJson []byte) error { return s.Put(storage.ImageDiffPath(imageID), diffJson) }