Merge "Zipalign: Avoid unnecessary padding" am: 50ec71eac8
Original change: https://android-review.googlesource.com/c/platform/build/+/1826624 Change-Id: I4a5cfe56ff9fc6788934c059eb5c35d42d7da4a4
This commit is contained in:
@@ -530,7 +530,7 @@ status_t ZipFile::alignEntry(android::ZipEntry* pEntry, uint32_t alignTo){
|
|||||||
// If the alignment is not what was requested, add some padding in the extra
|
// If the alignment is not what was requested, add some padding in the extra
|
||||||
// so the payload ends up where is requested.
|
// so the payload ends up where is requested.
|
||||||
uint64_t alignDiff = alignTo - (expectedPayloadOffset % alignTo);
|
uint64_t alignDiff = alignTo - (expectedPayloadOffset % alignTo);
|
||||||
if (alignDiff == 0)
|
if (alignDiff == alignTo)
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
return pEntry->addPadding(alignDiff);
|
return pEntry->addPadding(alignDiff);
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
|
|
||||||
using namespace android;
|
using namespace android;
|
||||||
|
using namespace base;
|
||||||
|
|
||||||
static std::string GetTestPath(const std::string& filename) {
|
static std::string GetTestPath(const std::string& filename) {
|
||||||
static std::string test_data_dir = android::base::GetExecutableDirectory() + "/tests/data/";
|
static std::string test_data_dir = android::base::GetExecutableDirectory() + "/tests/data/";
|
||||||
@@ -26,6 +27,34 @@ TEST(Align, Unaligned) {
|
|||||||
ASSERT_EQ(0, verified);
|
ASSERT_EQ(0, verified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Align, DoubleAligment) {
|
||||||
|
const std::string src = GetTestPath("unaligned.zip");
|
||||||
|
const std::string tmp = GetTestPath("da_aligned.zip");
|
||||||
|
const std::string dst = GetTestPath("da_d_aligner.zip");
|
||||||
|
|
||||||
|
int processed = process(src.c_str(), tmp.c_str(), 4, true, false, 4096);
|
||||||
|
ASSERT_EQ(0, processed);
|
||||||
|
|
||||||
|
int verified = verify(tmp.c_str(), 4, true, false);
|
||||||
|
ASSERT_EQ(0, verified);
|
||||||
|
|
||||||
|
// Align the result of the previous run. Essentially double aligning.
|
||||||
|
processed = process(tmp.c_str(), dst.c_str(), 4, true, false, 4096);
|
||||||
|
ASSERT_EQ(0, processed);
|
||||||
|
|
||||||
|
verified = verify(dst.c_str(), 4, true, false);
|
||||||
|
ASSERT_EQ(0, verified);
|
||||||
|
|
||||||
|
// Nothing should have changed between tmp and dst.
|
||||||
|
std::string tmp_content;
|
||||||
|
ASSERT_EQ(true, ReadFileToString(tmp, &tmp_content));
|
||||||
|
|
||||||
|
std::string dst_content;
|
||||||
|
ASSERT_EQ(true, ReadFileToString(dst, &dst_content));
|
||||||
|
|
||||||
|
ASSERT_EQ(tmp_content, dst_content);
|
||||||
|
}
|
||||||
|
|
||||||
// Align a zip featuring a hole at the beginning. The
|
// Align a zip featuring a hole at the beginning. The
|
||||||
// hole in the archive is a delete entry in the Central
|
// hole in the archive is a delete entry in the Central
|
||||||
// Directory.
|
// Directory.
|
||||||
|
Reference in New Issue
Block a user