Always reset timestamps in merge_zips
Jacoco uses ziptime and then merge_zips. merge_zips is already rewriting all the zip headers so its trivial to move the ziptime functionality into merge_zips. Bug: 308765940 Test: TestMergeZips Change-Id: I8158c0b99878492233ac01fde3820e1951c9088e
This commit is contained in:
parent
78567011cf
commit
fa24df6b23
2 changed files with 41 additions and 25 deletions
|
@ -96,7 +96,9 @@ func (ze ZipEntryFromZip) WriteToZip(dest string, zw *zip.Writer) error {
|
||||||
if err := ze.inputZip.Open(); err != nil {
|
if err := ze.inputZip.Open(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return zw.CopyFrom(ze.inputZip.Entries()[ze.index], dest)
|
entry := ze.inputZip.Entries()[ze.index]
|
||||||
|
entry.SetModTime(jar.DefaultTime)
|
||||||
|
return zw.CopyFrom(entry, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// a ZipEntryFromBuffer is a ZipEntryContents that pulls its content from a []byte
|
// a ZipEntryFromBuffer is a ZipEntryContents that pulls its content from a []byte
|
||||||
|
|
|
@ -22,40 +22,45 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"android/soong/jar"
|
"android/soong/jar"
|
||||||
"android/soong/third_party/zip"
|
"android/soong/third_party/zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testZipEntry struct {
|
type testZipEntry struct {
|
||||||
name string
|
name string
|
||||||
mode os.FileMode
|
mode os.FileMode
|
||||||
data []byte
|
data []byte
|
||||||
method uint16
|
method uint16
|
||||||
|
timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
A = testZipEntry{"A", 0755, []byte("foo"), zip.Deflate}
|
A = testZipEntry{"A", 0755, []byte("foo"), zip.Deflate, jar.DefaultTime}
|
||||||
a = testZipEntry{"a", 0755, []byte("foo"), zip.Deflate}
|
a = testZipEntry{"a", 0755, []byte("foo"), zip.Deflate, jar.DefaultTime}
|
||||||
a2 = testZipEntry{"a", 0755, []byte("FOO2"), zip.Deflate}
|
a2 = testZipEntry{"a", 0755, []byte("FOO2"), zip.Deflate, jar.DefaultTime}
|
||||||
a3 = testZipEntry{"a", 0755, []byte("Foo3"), zip.Deflate}
|
a3 = testZipEntry{"a", 0755, []byte("Foo3"), zip.Deflate, jar.DefaultTime}
|
||||||
bDir = testZipEntry{"b/", os.ModeDir | 0755, nil, zip.Deflate}
|
bDir = testZipEntry{"b/", os.ModeDir | 0755, nil, zip.Deflate, jar.DefaultTime}
|
||||||
bbDir = testZipEntry{"b/b/", os.ModeDir | 0755, nil, zip.Deflate}
|
bbDir = testZipEntry{"b/b/", os.ModeDir | 0755, nil, zip.Deflate, jar.DefaultTime}
|
||||||
bbb = testZipEntry{"b/b/b", 0755, nil, zip.Deflate}
|
bbb = testZipEntry{"b/b/b", 0755, nil, zip.Deflate, jar.DefaultTime}
|
||||||
ba = testZipEntry{"b/a", 0755, []byte("foo"), zip.Deflate}
|
ba = testZipEntry{"b/a", 0755, []byte("foo"), zip.Deflate, jar.DefaultTime}
|
||||||
bc = testZipEntry{"b/c", 0755, []byte("bar"), zip.Deflate}
|
bc = testZipEntry{"b/c", 0755, []byte("bar"), zip.Deflate, jar.DefaultTime}
|
||||||
bd = testZipEntry{"b/d", 0700, []byte("baz"), zip.Deflate}
|
bd = testZipEntry{"b/d", 0700, []byte("baz"), zip.Deflate, jar.DefaultTime}
|
||||||
be = testZipEntry{"b/e", 0700, []byte(""), zip.Deflate}
|
be = testZipEntry{"b/e", 0700, []byte(""), zip.Deflate, jar.DefaultTime}
|
||||||
|
|
||||||
service1a = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass2\n"), zip.Store}
|
withTimestamp = testZipEntry{"timestamped", 0755, nil, zip.Store, jar.DefaultTime.Add(time.Hour)}
|
||||||
service1b = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass3\n"), zip.Deflate}
|
withoutTimestamp = testZipEntry{"timestamped", 0755, nil, zip.Store, jar.DefaultTime}
|
||||||
service1combined = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass2\nclass3\n"), zip.Store}
|
|
||||||
service2 = testZipEntry{"META-INF/services/service2", 0755, []byte("class1\nclass2\n"), zip.Deflate}
|
|
||||||
|
|
||||||
metainfDir = testZipEntry{jar.MetaDir, os.ModeDir | 0755, nil, zip.Deflate}
|
service1a = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass2\n"), zip.Store, jar.DefaultTime}
|
||||||
manifestFile = testZipEntry{jar.ManifestFile, 0755, []byte("manifest"), zip.Deflate}
|
service1b = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass3\n"), zip.Deflate, jar.DefaultTime}
|
||||||
manifestFile2 = testZipEntry{jar.ManifestFile, 0755, []byte("manifest2"), zip.Deflate}
|
service1combined = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass2\nclass3\n"), zip.Store, jar.DefaultTime}
|
||||||
moduleInfoFile = testZipEntry{jar.ModuleInfoClass, 0755, []byte("module-info"), zip.Deflate}
|
service2 = testZipEntry{"META-INF/services/service2", 0755, []byte("class1\nclass2\n"), zip.Deflate, jar.DefaultTime}
|
||||||
|
|
||||||
|
metainfDir = testZipEntry{jar.MetaDir, os.ModeDir | 0755, nil, zip.Deflate, jar.DefaultTime}
|
||||||
|
manifestFile = testZipEntry{jar.ManifestFile, 0755, []byte("manifest"), zip.Deflate, jar.DefaultTime}
|
||||||
|
manifestFile2 = testZipEntry{jar.ManifestFile, 0755, []byte("manifest2"), zip.Deflate, jar.DefaultTime}
|
||||||
|
moduleInfoFile = testZipEntry{jar.ModuleInfoClass, 0755, []byte("module-info"), zip.Deflate, jar.DefaultTime}
|
||||||
)
|
)
|
||||||
|
|
||||||
type testInputZip struct {
|
type testInputZip struct {
|
||||||
|
@ -252,6 +257,14 @@ func TestMergeZips(t *testing.T) {
|
||||||
jar: true,
|
jar: true,
|
||||||
out: []testZipEntry{service1combined, service2},
|
out: []testZipEntry{service1combined, service2},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "strip timestamps",
|
||||||
|
in: [][]testZipEntry{
|
||||||
|
{withTimestamp},
|
||||||
|
{a},
|
||||||
|
},
|
||||||
|
out: []testZipEntry{withoutTimestamp, a},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
@ -307,6 +320,7 @@ func testZipEntriesToBuf(entries []testZipEntry) []byte {
|
||||||
}
|
}
|
||||||
fh.SetMode(e.mode)
|
fh.SetMode(e.mode)
|
||||||
fh.Method = e.method
|
fh.Method = e.method
|
||||||
|
fh.SetModTime(e.timestamp)
|
||||||
fh.UncompressedSize64 = uint64(len(e.data))
|
fh.UncompressedSize64 = uint64(len(e.data))
|
||||||
fh.CRC32 = crc32.ChecksumIEEE(e.data)
|
fh.CRC32 = crc32.ChecksumIEEE(e.data)
|
||||||
if fh.Method == zip.Store {
|
if fh.Method == zip.Store {
|
||||||
|
@ -354,7 +368,7 @@ func dumpZip(buf []byte) string {
|
||||||
var ret string
|
var ret string
|
||||||
|
|
||||||
for _, f := range zr.File {
|
for _, f := range zr.File {
|
||||||
ret += fmt.Sprintf("%v: %v %v %08x\n", f.Name, f.Mode(), f.UncompressedSize64, f.CRC32)
|
ret += fmt.Sprintf("%v: %v %v %08x %s\n", f.Name, f.Mode(), f.UncompressedSize64, f.CRC32, f.ModTime())
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Reference in a new issue