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
This commit is contained in:
parent
153c2f8ba3
commit
dc1e829b59
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,14 @@ func TestMergeZips(t *testing.T) {
|
|||
|
||||
ignoreDuplicates: true,
|
||||
},
|
||||
{
|
||||
name: "duplicates identical",
|
||||
in: [][]testZipEntry{
|
||||
{a},
|
||||
{a},
|
||||
},
|
||||
out: []testZipEntry{a},
|
||||
},
|
||||
{
|
||||
name: "sort",
|
||||
in: [][]testZipEntry{
|
||||
|
|
Loading…
Reference in New Issue