mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Validate adding digests to tagstore with go types
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		
							parent
							
								
									3422858653
								
							
						
					
					
						commit
						20e759ab56
					
				
					 9 changed files with 98 additions and 35 deletions
				
			
		| 
						 | 
				
			
			@ -190,7 +190,8 @@ func migrateContainers(root string, ls graphIDMounter, is image.Store, imageMapp
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
type tagAdder interface {
 | 
			
		||||
	Add(ref reference.Named, id image.ID, force bool) error
 | 
			
		||||
	AddTag(ref reference.Named, id image.ID, force bool) error
 | 
			
		||||
	AddDigest(ref reference.Canonical, id image.ID, force bool) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func migrateTags(root, driverName string, ts tagAdder, mappings map[string]image.ID) error {
 | 
			
		||||
| 
						 | 
				
			
			@ -226,20 +227,23 @@ func migrateTags(root, driverName string, ts tagAdder, mappings map[string]image
 | 
			
		|||
					continue
 | 
			
		||||
				}
 | 
			
		||||
				if dgst, err := digest.ParseDigest(tag); err == nil {
 | 
			
		||||
					ref, err = reference.WithDigest(ref, dgst)
 | 
			
		||||
					canonical, err := reference.WithDigest(ref, dgst)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err)
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
					if err := ts.AddDigest(canonical, strongID, false); err != nil {
 | 
			
		||||
						logrus.Errorf("can't migrate digest %q for %q, err: %q", ref.String(), strongID, err)
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					ref, err = reference.WithTag(ref, tag)
 | 
			
		||||
					tagRef, err := reference.WithTag(ref, tag)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						logrus.Errorf("migrate tags: invalid tag %q, %q", tag, err)
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				if err := ts.Add(ref, strongID, false); err != nil {
 | 
			
		||||
					logrus.Errorf("can't migrate tag %q for %q, err: %q", ref.String(), strongID, err)
 | 
			
		||||
					if err := ts.AddTag(tagRef, strongID, false); err != nil {
 | 
			
		||||
						logrus.Errorf("can't migrate tag %q for %q, err: %q", ref.String(), strongID, err)
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				logrus.Infof("migrated tag %s:%s to point to %s", name, tag, strongID)
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -289,13 +289,16 @@ type mockTagAdder struct {
 | 
			
		|||
	refs map[string]string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t *mockTagAdder) Add(ref reference.Named, id image.ID, force bool) error {
 | 
			
		||||
func (t *mockTagAdder) AddTag(ref reference.Named, id image.ID, force bool) error {
 | 
			
		||||
	if t.refs == nil {
 | 
			
		||||
		t.refs = make(map[string]string)
 | 
			
		||||
	}
 | 
			
		||||
	t.refs[ref.String()] = id.String()
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
func (t *mockTagAdder) AddDigest(ref reference.Canonical, id image.ID, force bool) error {
 | 
			
		||||
	return t.AddTag(ref, id, force)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type mockRegistrar struct {
 | 
			
		||||
	layers map[layer.ChainID]*mockLayer
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue