Merge "Move zipalign off NO_ERROR."
am: 3f7223984c
Change-Id: I37e953bd989d5f04b42129eef876c1aff4d162fb
This commit is contained in:
@@ -111,7 +111,7 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfl
|
|||||||
status = pZout->add(pZin, pEntry, padding, &pNewEntry);
|
status = pZout->add(pZin, pEntry, padding, &pNewEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != NO_ERROR)
|
if (status != OK)
|
||||||
return 1;
|
return 1;
|
||||||
bias += padding;
|
bias += padding;
|
||||||
//printf(" added '%s' at %ld (pad=%d)\n",
|
//printf(" added '%s' at %ld (pad=%d)\n",
|
||||||
@@ -146,13 +146,13 @@ static int process(const char* inFileName, const char* outFileName,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zin.open(inFileName, ZipFile::kOpenReadOnly) != NO_ERROR) {
|
if (zin.open(inFileName, ZipFile::kOpenReadOnly) != OK) {
|
||||||
fprintf(stderr, "Unable to open '%s' as zip archive\n", inFileName);
|
fprintf(stderr, "Unable to open '%s' as zip archive\n", inFileName);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (zout.open(outFileName,
|
if (zout.open(outFileName,
|
||||||
ZipFile::kOpenReadWrite|ZipFile::kOpenCreate|ZipFile::kOpenTruncate)
|
ZipFile::kOpenReadWrite|ZipFile::kOpenCreate|ZipFile::kOpenTruncate)
|
||||||
!= NO_ERROR)
|
!= OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to open '%s' as zip archive\n", outFileName);
|
fprintf(stderr, "Unable to open '%s' as zip archive\n", outFileName);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -178,7 +178,7 @@ static int verify(const char* fileName, int alignment, bool verbose,
|
|||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Verifying alignment of %s (%d)...\n", fileName, alignment);
|
printf("Verifying alignment of %s (%d)...\n", fileName, alignment);
|
||||||
|
|
||||||
if (zipFile.open(fileName, ZipFile::kOpenReadOnly) != NO_ERROR) {
|
if (zipFile.open(fileName, ZipFile::kOpenReadOnly) != OK) {
|
||||||
fprintf(stderr, "Unable to open '%s' for verification\n", fileName);
|
fprintf(stderr, "Unable to open '%s' for verification\n", fileName);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ status_t ZipEntry::initFromCDE(FILE* fp)
|
|||||||
|
|
||||||
/* read the CDE */
|
/* read the CDE */
|
||||||
result = mCDE.read(fp);
|
result = mCDE.read(fp);
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
ALOGD("mCDE.read failed\n");
|
ALOGD("mCDE.read failed\n");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ status_t ZipEntry::initFromCDE(FILE* fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = mLFH.read(fp);
|
result = mLFH.read(fp);
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
ALOGD("mLFH.read failed\n");
|
ALOGD("mLFH.read failed\n");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ status_t ZipEntry::initFromCDE(FILE* fp)
|
|||||||
* can defer worrying about that to when we're extracting data.
|
* can defer worrying about that to when we're extracting data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -189,7 +189,7 @@ status_t ZipEntry::initFromExternal(const ZipEntry* pEntry)
|
|||||||
mLFH.mExtraFieldLength+1);
|
mLFH.mExtraFieldLength+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -225,7 +225,7 @@ status_t ZipEntry::addPadding(int padding)
|
|||||||
mLFH.mExtraFieldLength = padding;
|
mLFH.mExtraFieldLength = padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -403,7 +403,7 @@ void ZipEntry::setModWhen(time_t when)
|
|||||||
*/
|
*/
|
||||||
status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
uint8_t buf[kLFHLen];
|
uint8_t buf[kLFHLen];
|
||||||
|
|
||||||
assert(mFileName == NULL);
|
assert(mFileName == NULL);
|
||||||
@@ -499,7 +499,7 @@ status_t ZipEntry::LocalFileHeader::write(FILE* fp)
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -537,7 +537,7 @@ void ZipEntry::LocalFileHeader::dump(void) const
|
|||||||
*/
|
*/
|
||||||
status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
uint8_t buf[kCDELen];
|
uint8_t buf[kCDELen];
|
||||||
|
|
||||||
/* no re-use */
|
/* no re-use */
|
||||||
@@ -669,7 +669,7 @@ status_t ZipEntry::CentralDirEntry::write(FILE* fp)
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -120,7 +120,7 @@ status_t ZipFile::open(const char* zipFileName, int flags)
|
|||||||
* have a need for empty zip files.)
|
* have a need for empty zip files.)
|
||||||
*/
|
*/
|
||||||
mNeedCDRewrite = true;
|
mNeedCDRewrite = true;
|
||||||
result = NO_ERROR;
|
result = OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & kOpenReadOnly)
|
if (flags & kOpenReadOnly)
|
||||||
@@ -205,7 +205,7 @@ void ZipFile::discardEntries(void)
|
|||||||
*/
|
*/
|
||||||
status_t ZipFile::readCentralDir(void)
|
status_t ZipFile::readCentralDir(void)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
uint8_t* buf = NULL;
|
uint8_t* buf = NULL;
|
||||||
off_t fileLength, seekStart;
|
off_t fileLength, seekStart;
|
||||||
long readAmount;
|
long readAmount;
|
||||||
@@ -267,7 +267,7 @@ status_t ZipFile::readCentralDir(void)
|
|||||||
|
|
||||||
/* extract eocd values */
|
/* extract eocd values */
|
||||||
result = mEOCD.readBuf(buf + i, readAmount - i);
|
result = mEOCD.readBuf(buf + i, readAmount - i);
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
ALOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
|
ALOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@@ -311,7 +311,7 @@ status_t ZipFile::readCentralDir(void)
|
|||||||
ZipEntry* pEntry = new ZipEntry;
|
ZipEntry* pEntry = new ZipEntry;
|
||||||
|
|
||||||
result = pEntry->initFromCDE(mZipFp);
|
result = pEntry->initFromCDE(mZipFp);
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
ALOGD("initFromCDE failed\n");
|
ALOGD("initFromCDE failed\n");
|
||||||
delete pEntry;
|
delete pEntry;
|
||||||
goto bail;
|
goto bail;
|
||||||
@@ -361,7 +361,7 @@ status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
|
|||||||
const char* storageName, int compressionMethod, ZipEntry** ppEntry)
|
const char* storageName, int compressionMethod, ZipEntry** ppEntry)
|
||||||
{
|
{
|
||||||
ZipEntry* pEntry = NULL;
|
ZipEntry* pEntry = NULL;
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
long lfhPosn, startPosn, endPosn, uncompressedLen;
|
long lfhPosn, startPosn, endPosn, uncompressedLen;
|
||||||
FILE* inputFp = NULL;
|
FILE* inputFp = NULL;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
@@ -415,7 +415,7 @@ status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
|
|||||||
if (compressionMethod == ZipEntry::kCompressDeflated) {
|
if (compressionMethod == ZipEntry::kCompressDeflated) {
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
|
result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
ALOGD("compression failed, storing\n");
|
ALOGD("compression failed, storing\n");
|
||||||
failed = true;
|
failed = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -447,7 +447,7 @@ status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
|
|||||||
} else {
|
} else {
|
||||||
result = copyDataToFp(mZipFp, data, size, &crc);
|
result = copyDataToFp(mZipFp, data, size, &crc);
|
||||||
}
|
}
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
// don't need to truncate; happens in CDE rewrite
|
// don't need to truncate; happens in CDE rewrite
|
||||||
ALOGD("failed copying data in\n");
|
ALOGD("failed copying data in\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
@@ -535,11 +535,11 @@ status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = pEntry->initFromExternal(pSourceEntry);
|
result = pEntry->initFromExternal(pSourceEntry);
|
||||||
if (result != NO_ERROR)
|
if (result != OK)
|
||||||
goto bail;
|
goto bail;
|
||||||
if (padding != 0) {
|
if (padding != 0) {
|
||||||
result = pEntry->addPadding(padding);
|
result = pEntry->addPadding(padding);
|
||||||
if (result != NO_ERROR)
|
if (result != OK)
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +574,7 @@ status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
|
|||||||
copyLen += ZipEntry::kDataDescriptorLen;
|
copyLen += ZipEntry::kDataDescriptorLen;
|
||||||
|
|
||||||
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
|
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
|
||||||
!= NO_ERROR)
|
!= OK)
|
||||||
{
|
{
|
||||||
ALOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
|
ALOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
|
||||||
result = UNKNOWN_ERROR;
|
result = UNKNOWN_ERROR;
|
||||||
@@ -603,7 +603,7 @@ status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
|
|||||||
*ppEntry = pEntry;
|
*ppEntry = pEntry;
|
||||||
pEntry = NULL;
|
pEntry = NULL;
|
||||||
|
|
||||||
result = NO_ERROR;
|
result = OK;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
delete pEntry;
|
delete pEntry;
|
||||||
@@ -642,7 +642,7 @@ status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSour
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = pEntry->initFromExternal(pSourceEntry);
|
result = pEntry->initFromExternal(pSourceEntry);
|
||||||
if (result != NO_ERROR)
|
if (result != OK)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -682,7 +682,7 @@ status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSour
|
|||||||
}
|
}
|
||||||
long startPosn = ftell(mZipFp);
|
long startPosn = ftell(mZipFp);
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
if (compressFpToFp(mZipFp, NULL, buf, uncompressedLen, &crc) != NO_ERROR) {
|
if (compressFpToFp(mZipFp, NULL, buf, uncompressedLen, &crc) != OK) {
|
||||||
ALOGW("recompress of '%s' failed\n", pEntry->mCDE.mFileName);
|
ALOGW("recompress of '%s' failed\n", pEntry->mCDE.mFileName);
|
||||||
result = UNKNOWN_ERROR;
|
result = UNKNOWN_ERROR;
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -699,7 +699,7 @@ status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSour
|
|||||||
copyLen += ZipEntry::kDataDescriptorLen;
|
copyLen += ZipEntry::kDataDescriptorLen;
|
||||||
|
|
||||||
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
|
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
|
||||||
!= NO_ERROR)
|
!= OK)
|
||||||
{
|
{
|
||||||
ALOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
|
ALOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
|
||||||
result = UNKNOWN_ERROR;
|
result = UNKNOWN_ERROR;
|
||||||
@@ -738,7 +738,7 @@ status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSour
|
|||||||
*ppEntry = pEntry;
|
*ppEntry = pEntry;
|
||||||
pEntry = NULL;
|
pEntry = NULL;
|
||||||
|
|
||||||
result = NO_ERROR;
|
result = OK;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
delete pEntry;
|
delete pEntry;
|
||||||
@@ -773,7 +773,7 @@ status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, uint32_t* pCRC32)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -793,7 +793,7 @@ status_t ZipFile::copyDataToFp(FILE* dstFp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -837,7 +837,7 @@ status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, size_t length,
|
|||||||
length -= readSize;
|
length -= readSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -849,7 +849,7 @@ status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, size_t length,
|
|||||||
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
|
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
|
||||||
const void* data, size_t size, uint32_t* pCRC32)
|
const void* data, size_t size, uint32_t* pCRC32)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
const size_t kBufSize = 1024 * 1024;
|
const size_t kBufSize = 1024 * 1024;
|
||||||
uint8_t* inBuf = NULL;
|
uint8_t* inBuf = NULL;
|
||||||
uint8_t* outBuf = NULL;
|
uint8_t* outBuf = NULL;
|
||||||
@@ -933,7 +933,7 @@ status_t ZipFile::remove(ZipEntry* pEntry)
|
|||||||
/* mark entry as deleted, and mark archive as dirty */
|
/* mark entry as deleted, and mark archive as dirty */
|
||||||
pEntry->setDeleted();
|
pEntry->setDeleted();
|
||||||
mNeedCDRewrite = true;
|
mNeedCDRewrite = true;
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -944,19 +944,19 @@ status_t ZipFile::remove(ZipEntry* pEntry)
|
|||||||
*/
|
*/
|
||||||
status_t ZipFile::flush(void)
|
status_t ZipFile::flush(void)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
long eocdPosn;
|
long eocdPosn;
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
if (mReadOnly)
|
if (mReadOnly)
|
||||||
return INVALID_OPERATION;
|
return INVALID_OPERATION;
|
||||||
if (!mNeedCDRewrite)
|
if (!mNeedCDRewrite)
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
|
|
||||||
assert(mZipFp != NULL);
|
assert(mZipFp != NULL);
|
||||||
|
|
||||||
result = crunchArchive();
|
result = crunchArchive();
|
||||||
if (result != NO_ERROR)
|
if (result != OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0)
|
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0)
|
||||||
@@ -986,7 +986,7 @@ status_t ZipFile::flush(void)
|
|||||||
/* should we clear the "newly added" flag in all entries now? */
|
/* should we clear the "newly added" flag in all entries now? */
|
||||||
|
|
||||||
mNeedCDRewrite = false;
|
mNeedCDRewrite = false;
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -997,7 +997,7 @@ status_t ZipFile::flush(void)
|
|||||||
*/
|
*/
|
||||||
status_t ZipFile::crunchArchive(void)
|
status_t ZipFile::crunchArchive(void)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = OK;
|
||||||
int i, count;
|
int i, count;
|
||||||
long delCount, adjust;
|
long delCount, adjust;
|
||||||
|
|
||||||
@@ -1065,7 +1065,7 @@ status_t ZipFile::crunchArchive(void)
|
|||||||
// pEntry->getFileName(), adjust);
|
// pEntry->getFileName(), adjust);
|
||||||
result = filemove(mZipFp, pEntry->getLFHOffset() - adjust,
|
result = filemove(mZipFp, pEntry->getLFHOffset() - adjust,
|
||||||
pEntry->getLFHOffset(), span);
|
pEntry->getLFHOffset(), span);
|
||||||
if (result != NO_ERROR) {
|
if (result != OK) {
|
||||||
/* this is why you use a temp file */
|
/* this is why you use a temp file */
|
||||||
ALOGE("error during crunch - archive is toast\n");
|
ALOGE("error during crunch - archive is toast\n");
|
||||||
return result;
|
return result;
|
||||||
@@ -1097,7 +1097,7 @@ status_t ZipFile::crunchArchive(void)
|
|||||||
status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
|
status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
|
||||||
{
|
{
|
||||||
if (dst == src || n <= 0)
|
if (dst == src || n <= 0)
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
|
|
||||||
uint8_t readBuf[32768];
|
uint8_t readBuf[32768];
|
||||||
|
|
||||||
@@ -1140,7 +1140,7 @@ status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1355,7 +1355,7 @@ status_t ZipFile::EndOfCentralDir::readBuf(const uint8_t* buf, int len)
|
|||||||
memcpy(mComment, buf + kEOCDLen, mCommentLen);
|
memcpy(mComment, buf + kEOCDLen, mCommentLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1382,7 +1382,7 @@ status_t ZipFile::EndOfCentralDir::write(FILE* fp)
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user