Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 2744bfe

Browse files
committed
Merge remote-tracking branch 'upstream/master' into SizeSorting
2 parents 9f20ce6 + 773aca0 commit 2744bfe

File tree

4 files changed

+24
-42
lines changed

4 files changed

+24
-42
lines changed

tests/multi_diff_expected.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,6 @@
124124
"Size": 73348
125125
}
126126
]
127-
},
128-
{
129-
"Package": "setuptools",
130-
"Info1": [
131-
{
132-
"Version": "36.2.2",
133-
"Size": 839895
134-
}
135-
],
136-
"Info2": [
137-
{
138-
"Version": "36.2.2",
139-
"Size": 1157078
140-
}
141-
]
142-
},
143-
{
144-
"Package": "wheel",
145-
"Info1": [
146-
{
147-
"Version": "0.29.0",
148-
"Size": 103509
149-
}
150-
],
151-
"Info2": [
152-
{
153-
"Version": "0.29.0",
154-
"Size": 137451
155-
}
156-
]
157127
}
158128
]
159129
}

utils/package_diff_utils.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func multiVersionDiff(infoDiff []MultiVersionInfo, packageName string, map1, map
5252
diff1 = append(diff1, packInfo1)
5353
continue
5454
} else {
55-
if reflect.DeepEqual(packInfo1, packInfo2) {
55+
// If a package instance is installed in the same place in Image1 and Image2 with the same version,
56+
// then they are the same package and should not be included in the diff
57+
if packInfo1.Version == packInfo2.Version {
5658
delete(map2, path)
5759
} else {
5860
diff1 = append(diff1, packInfo1)
@@ -127,25 +129,36 @@ func diffMaps(map1, map2 interface{}) interface{} {
127129
for _, pack := range map1Value.MapKeys() {
128130
packageEntry1 := map1Value.MapIndex(pack)
129131
packageEntry2 := map2Value.MapIndex(pack)
132+
// If the package does not exist in Image2's map of packages, add it to the collection of unique packages in Image1
130133
if !packageEntry2.IsValid() {
131134
diff1.SetMapIndex(pack, packageEntry1)
132-
} else if !reflect.DeepEqual(packageEntry2.Interface(), packageEntry1.Interface()) {
135+
// If the package exists in Image2's map of packages but the package information differs between images, add it to
136+
// the difference. Otherwise, if the information is consistent across images, delete it from the Image2's map of packages.
137+
} else {
133138
if multiV {
134-
multiInfoDiff = multiVersionDiff(multiInfoDiff, pack.String(),
135-
packageEntry1.Interface().(map[string]PackageInfo), packageEntry2.Interface().(map[string]PackageInfo))
139+
if !reflect.DeepEqual(packageEntry2.Interface(), packageEntry1.Interface()) {
140+
multiInfoDiff = multiVersionDiff(multiInfoDiff, pack.String(),
141+
packageEntry1.Interface().(map[string]PackageInfo),
142+
packageEntry2.Interface().(map[string]PackageInfo))
143+
}
136144
} else {
137-
infoDiff = append(infoDiff, Info{pack.String(), packageEntry1.Interface().(PackageInfo),
138-
packageEntry2.Interface().(PackageInfo)})
145+
packageInfo1 := packageEntry1.Interface().(PackageInfo)
146+
packageInfo2 := packageEntry2.Interface().(PackageInfo)
147+
// If two instances of the same package don't have the same version, then they are considered to be different
148+
if packageInfo1.Version != packageInfo2.Version {
149+
infoDiff = append(infoDiff, Info{pack.String(), packageInfo1, packageInfo2})
150+
}
139151
}
140152
map2Value.SetMapIndex(pack, reflect.Value{})
141-
} else {
142-
map2Value.SetMapIndex(pack, reflect.Value{})
143153
}
144154
}
155+
156+
// The packages remaining in Image2's map of images are those that exist uniquely in Image2
145157
for _, key2 := range map2Value.MapKeys() {
146158
packageEntry2 := map2Value.MapIndex(key2)
147159
diff2.SetMapIndex(key2, packageEntry2)
148160
}
161+
149162
if multiV {
150163
return MultiVersionPackageDiff{Packages1: diff1.Interface().(map[string]map[string]PackageInfo),
151164
Packages2: diff2.Interface().(map[string]map[string]PackageInfo), InfoDiff: multiInfoDiff}

utils/package_diff_utils_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func TestDiffMaps(t *testing.T) {
6060
Packages1: map[string]PackageInfo{},
6161
Packages2: map[string]PackageInfo{},
6262
InfoDiff: []Info{
63-
{"pac2", PackageInfo{"2.0", 50}, PackageInfo{"2.0", 45}},
6463
{"pac3", PackageInfo{"3.0", 60}, PackageInfo{"4.0", 60}}},
6564
},
6665
},
@@ -141,7 +140,7 @@ func TestDiffMaps(t *testing.T) {
141140
sort.Sort(ByPackage(expected.InfoDiff))
142141
sort.Sort(ByPackage(actual.InfoDiff))
143142
if !reflect.DeepEqual(expected, actual) {
144-
t.Errorf("expected Diff to be: %s but got:%s", expected, actual)
143+
t.Errorf("expected Diff to be: %v but got:%v", expected, actual)
145144
return
146145
}
147146
case MultiVersionPackageDiff:
@@ -158,7 +157,7 @@ func TestDiffMaps(t *testing.T) {
158157
sort.Sort(ByPackageInfo(pack2.Info2))
159158
}
160159
if !reflect.DeepEqual(expected, actual) {
161-
t.Errorf("expected Diff to be: %s but got:%s", expected, actual)
160+
t.Errorf("expected Diff to be: %v but got:%v", expected, actual)
162161
return
163162
}
164163
}

utils/tar_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func unpackTar(tr *tar.Reader, path string) error {
5858
glog.Errorf("Error opening file %s", target)
5959
return err
6060
}
61-
defer currFile.Close()
6261
_, err = io.Copy(currFile, tr)
6362
if err != nil {
6463
return err
6564
}
65+
currFile.Close()
6666
}
6767

6868
}

0 commit comments

Comments
 (0)