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

Merge pull request #41884 from rcowsill/41829-load-valid-parent

Fix spurious error from "docker load"
This commit is contained in:
Sebastiaan van Stijn 2021-02-22 22:00:29 +01:00 committed by GitHub
commit 4a054ec00f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"reflect"
"runtime" "runtime"
"strings" "strings"
"time" "time"
@ -218,6 +219,16 @@ func NewHistory(author, comment, createdBy string, isEmptyLayer bool) History {
} }
} }
// Equal compares two history structs for equality
func (h History) Equal(i History) bool {
if !h.Created.Equal(i.Created) {
return false
}
i.Created = h.Created
return reflect.DeepEqual(h, i)
}
// Exporter provides interface for loading and saving images // Exporter provides interface for loading and saving images
type Exporter interface { type Exporter interface {
Load(io.ReadCloser, io.Writer, bool) error Load(io.ReadCloser, io.Writer, bool) error

View file

@ -56,6 +56,29 @@ func TestMarshalKeyOrder(t *testing.T) {
} }
} }
const sampleHistoryJSON = `{
"created": "2021-01-13T09:35:56Z",
"created_by": "image_test.go"
}`
func TestHistoryEqual(t *testing.T) {
h := historyFromJSON(t, sampleHistoryJSON)
hCopy := h
assert.Check(t, h.Equal(hCopy))
hUTC := historyFromJSON(t, `{"created": "2021-01-13T14:00:00Z"}`)
hOffset0 := historyFromJSON(t, `{"created": "2021-01-13T14:00:00+00:00"}`)
assert.Check(t, hUTC.Created != hOffset0.Created)
assert.Check(t, hUTC.Equal(hOffset0))
}
func historyFromJSON(t *testing.T, historyJSON string) History {
var h History
err := json.Unmarshal([]byte(historyJSON), &h)
assert.Check(t, err)
return h
}
func TestImage(t *testing.T) { func TestImage(t *testing.T) {
cid := "50a16564e727" cid := "50a16564e727"
config := &container.Config{ config := &container.Config{

View file

@ -8,7 +8,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"runtime" "runtime"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
@ -410,7 +409,7 @@ func checkValidParent(img, parent *image.Image) bool {
return false return false
} }
for i, h := range parent.History { for i, h := range parent.History {
if !reflect.DeepEqual(h, img.History[i]) { if !h.Equal(img.History[i]) {
return false return false
} }
} }