|
@@ -102,7 +102,7 @@ func (index *Index) Find(idOrName string) *Image {
|
|
|
}
|
|
|
// Lookup by name
|
|
|
if history, exists := index.ByName[idOrName]; exists && history.Len() > 0 {
|
|
|
- return (*history)[0].(*Image)
|
|
|
+ return (*history)[0]
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
@@ -116,7 +116,7 @@ func (index *Index) Add(name string, image *Image) error {
|
|
|
index.ByName[name] = new(History)
|
|
|
} else {
|
|
|
// If this image is already the latest version, don't add it.
|
|
|
- if (*index.ByName[name])[0].(*Image).Id == image.Id {
|
|
|
+ if (*index.ByName[name])[0].Id == image.Id {
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
@@ -169,8 +169,7 @@ func (index *Index) Rename(oldName, newName string) error {
|
|
|
index.ByName[newName] = index.ByName[oldName]
|
|
|
delete(index.ByName, oldName)
|
|
|
// Change the ID of all images, since they include the name
|
|
|
- for _, event := range *index.ByName[newName] {
|
|
|
- image := event.(*Image)
|
|
|
+ for _, image := range *index.ByName[newName] {
|
|
|
if id, err := generateImageId(newName, image.Layers); err != nil {
|
|
|
return err
|
|
|
} else {
|
|
@@ -228,33 +227,37 @@ func (index *Index) save() error {
|
|
|
|
|
|
// History wraps an array of images so they can be sorted by date (most recent first)
|
|
|
|
|
|
-type Event interface {
|
|
|
- When() time.Time
|
|
|
-}
|
|
|
-
|
|
|
-type History []Event
|
|
|
+type History []*Image
|
|
|
|
|
|
func (history *History) Len() int {
|
|
|
return len(*history)
|
|
|
}
|
|
|
|
|
|
func (history *History) Less(i, j int) bool {
|
|
|
- events := *history
|
|
|
- return events[j].When().Before(events[i].When())
|
|
|
+ images := *history
|
|
|
+ return images[j].Created.Before(images[i].Created)
|
|
|
}
|
|
|
|
|
|
func (history *History) Swap(i, j int) {
|
|
|
- events := *history
|
|
|
- tmp := events[i]
|
|
|
- events[i] = events[j]
|
|
|
- events[j] = tmp
|
|
|
+ images := *history
|
|
|
+ tmp := images[i]
|
|
|
+ images[i] = images[j]
|
|
|
+ images[j] = tmp
|
|
|
}
|
|
|
|
|
|
-func (history *History) Add(event Event) {
|
|
|
- *history = append(*history, event)
|
|
|
+func (history *History) Add(image *Image) {
|
|
|
+ *history = append(*history, image)
|
|
|
sort.Sort(history)
|
|
|
}
|
|
|
|
|
|
+func (history *History) Del(id string) {
|
|
|
+ for idx, image := range *history {
|
|
|
+ if image.Id == id {
|
|
|
+ *history = append((*history)[:idx], (*history)[idx + 1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type Image struct {
|
|
|
Id string // Globally unique identifier
|
|
|
Layers []string // Absolute paths
|
|
@@ -262,10 +265,6 @@ type Image struct {
|
|
|
Parent string
|
|
|
}
|
|
|
|
|
|
-func (image *Image) When() time.Time {
|
|
|
- return image.Created
|
|
|
-}
|
|
|
-
|
|
|
func (image *Image) IdParts() (string, string) {
|
|
|
if len(image.Id) < 8 {
|
|
|
return "", image.Id
|