aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-10-17 15:05:56 -0700
committerColin Cross <ccross@android.com>2018-10-17 15:49:53 -0700
commitdc1e829b59fe97489180e38d8d8783468a3b9453 (patch)
tree07044e59044c21eb2e9affde34406cda96bed7c9 /cmd
parent153c2f8ba339cce73881570a6c7c2a51b0013d50 (diff)
downloadbuild_soong-dc1e829b59fe97489180e38d8d8783468a3b9453.tar.gz
build_soong-dc1e829b59fe97489180e38d8d8783468a3b9453.tar.bz2
build_soong-dc1e829b59fe97489180e38d8d8783468a3b9453.zip
Always allow duplicates with identical CRC32 and size
Don't warn on duplicate files in merge_zips if they have identical CRC32 and size values. Test: m checkbuild Test: merge_zips_test.go Change-Id: I61336ca4d4d3b7402c24a7abd337bd350fe10930
Diffstat (limited to 'cmd')
-rw-r--r--cmd/merge_zips/merge_zips.go31
-rw-r--r--cmd/merge_zips/merge_zips_test.go8
2 files changed, 29 insertions, 10 deletions
diff --git a/cmd/merge_zips/merge_zips.go b/cmd/merge_zips/merge_zips.go
index f383de90..8e71a978 100644
--- a/cmd/merge_zips/merge_zips.go
+++ b/cmd/merge_zips/merge_zips.go
@@ -173,6 +173,10 @@ func (ze zipEntry) CRC32() uint32 {
return ze.content.FileHeader.CRC32
}
+func (ze zipEntry) Size() uint64 {
+ return ze.content.FileHeader.UncompressedSize64
+}
+
func (ze zipEntry) WriteToZip(dest string, zw *zip.Writer) error {
return zw.CopyFrom(ze.content, dest)
}
@@ -195,6 +199,10 @@ func (be bufferEntry) CRC32() uint32 {
return crc32.ChecksumIEEE(be.content)
}
+func (be bufferEntry) Size() uint64 {
+ return uint64(len(be.content))
+}
+
func (be bufferEntry) WriteToZip(dest string, zw *zip.Writer) error {
w, err := zw.CreateHeader(be.fh)
if err != nil {
@@ -215,6 +223,7 @@ type zipSource interface {
String() string
IsDir() bool
CRC32() uint32
+ Size() uint64
WriteToZip(dest string, zw *zip.Writer) error
}
@@ -369,25 +378,27 @@ func mergeZips(readers []namedZipReader, writer *zip.Writer, manifest, entrypoin
return fmt.Errorf("Directory/file mismatch at %v from %v and %v\n",
dest, existingSource, source)
}
+
if ignoreDuplicates {
continue
}
+
if emulateJar &&
file.Name == jar.ManifestFile || file.Name == jar.ModuleInfoClass {
// Skip manifest and module info files that are not from the first input file
continue
}
- if !source.IsDir() {
- if emulateJar {
- if existingSource.CRC32() != source.CRC32() {
- fmt.Fprintf(os.Stdout, "WARNING: Duplicate path %v found in %v and %v\n",
- dest, existingSource, source)
- }
- } else {
- return fmt.Errorf("Duplicate path %v found in %v and %v\n",
- dest, existingSource, source)
- }
+
+ if source.IsDir() {
+ continue
+ }
+
+ if existingSource.CRC32() == source.CRC32() && existingSource.Size() == source.Size() {
+ continue
}
+
+ return fmt.Errorf("Duplicate path %v found in %v and %v\n",
+ dest, existingSource, source)
}
}
}
diff --git a/cmd/merge_zips/merge_zips_test.go b/cmd/merge_zips/merge_zips_test.go
index f91111f1..19fa5edd 100644
--- a/cmd/merge_zips/merge_zips_test.go
+++ b/cmd/merge_zips/merge_zips_test.go
@@ -88,6 +88,14 @@ func TestMergeZips(t *testing.T) {
ignoreDuplicates: true,
},
{
+ name: "duplicates identical",
+ in: [][]testZipEntry{
+ {a},
+ {a},
+ },
+ out: []testZipEntry{a},
+ },
+ {
name: "sort",
in: [][]testZipEntry{
{be, bc, bDir, bbDir, bbb, A, metainfDir, manifestFile},