Skip to content

Commit 20f6a24

Browse files
authored
Merge pull request #159 from veraicon/fixManifestCompare
修复manifestEqual方法缺陷
2 parents 18f32f5 + 83414dd commit 20f6a24

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pkg/sync/destination.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package sync
22

33
import (
4-
"bytes"
54
"context"
65
"encoding/json"
76
"fmt"
87
"io"
8+
"reflect"
99
"strings"
1010

1111
"github.com/AliyunContainerService/image-syncer/pkg/utils/auth"
@@ -214,11 +214,16 @@ func (i *ImageDestination) String() string {
214214
}
215215

216216
func manifestEqual(m1, m2 []byte) bool {
217-
var a bytes.Buffer
218-
_ = json.Compact(&a, m1)
217+
var a map[string]interface{}
218+
var b map[string]interface{}
219219

220-
var b bytes.Buffer
221-
_ = json.Compact(&b, m2)
220+
if err := json.Unmarshal(m1, &a); err != nil {
221+
//Received an unexpected manifest retrieval result, return false to trigger a fallback to the push task.
222+
return false
223+
}
224+
if err := json.Unmarshal(m2, &b); err != nil {
225+
return false
226+
}
222227

223-
return a.String() == b.String()
228+
return reflect.DeepEqual(a, b)
224229
}

0 commit comments

Comments
 (0)