projects
/
android
/
aapt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add single crunch command to aapt. do not merge.
[android/aapt.git]
/
ZipFile.cpp
diff --git
a/ZipFile.cpp
b/ZipFile.cpp
index 62c9383fc22a5f9c1c327c943b7f0091b6bcdc58..3994c3190a74f84248a18df50a722bd057bf33a4 100644
(file)
--- a/
ZipFile.cpp
+++ b/
ZipFile.cpp
@@
-20,8
+20,8
@@
#define LOG_TAG "zip"
#define LOG_TAG "zip"
-#include <utils/ZipUtils.h>
#include <utils/Log.h>
#include <utils/Log.h>
+#include <utils/ZipUtils.h>
#include "ZipFile.h"
#include "ZipFile.h"
@@
-78,7
+78,7
@@
status_t ZipFile::open(const char* zipFileName, int flags)
newArchive = (access(zipFileName, F_OK) != 0);
if (!(flags & kOpenCreate) && newArchive) {
/* not creating, must already exist */
newArchive = (access(zipFileName, F_OK) != 0);
if (!(flags & kOpenCreate) && newArchive) {
/* not creating, must already exist */
- LOGD("File %s does not exist", zipFileName);
+
A
LOGD("File %s does not exist", zipFileName);
return NAME_NOT_FOUND;
}
}
return NAME_NOT_FOUND;
}
}
@@
-96,7
+96,7
@@
status_t ZipFile::open(const char* zipFileName, int flags)
mZipFp = fopen(zipFileName, openflags);
if (mZipFp == NULL) {
int err = errno;
mZipFp = fopen(zipFileName, openflags);
if (mZipFp == NULL) {
int err = errno;
- LOGD("fopen failed: %d\n", err);
+
A
LOGD("fopen failed: %d\n", err);
return errnoToStatus(err);
}
return errnoToStatus(err);
}
@@
-215,14
+215,14
@@
status_t ZipFile::readCentralDir(void)
/* too small to be a ZIP archive? */
if (fileLength < EndOfCentralDir::kEOCDLen) {
/* too small to be a ZIP archive? */
if (fileLength < EndOfCentralDir::kEOCDLen) {
- LOGD("Length is %ld -- too small\n", (long)fileLength);
+
A
LOGD("Length is %ld -- too small\n", (long)fileLength);
result = INVALID_OPERATION;
goto bail;
}
buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
if (buf == NULL) {
result = INVALID_OPERATION;
goto bail;
}
buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
if (buf == NULL) {
- LOGD("Failure allocating %d bytes for EOCD search",
+
A
LOGD("Failure allocating %d bytes for EOCD search",
EndOfCentralDir::kMaxEOCDSearch);
result = NO_MEMORY;
goto bail;
EndOfCentralDir::kMaxEOCDSearch);
result = NO_MEMORY;
goto bail;
@@
-236,14
+236,14
@@
status_t ZipFile::readCentralDir(void)
readAmount = (long) fileLength;
}
if (fseek(mZipFp, seekStart, SEEK_SET) != 0) {
readAmount = (long) fileLength;
}
if (fseek(mZipFp, seekStart, SEEK_SET) != 0) {
- LOGD("Failure seeking to end of zip at %ld", (long) seekStart);
+
A
LOGD("Failure seeking to end of zip at %ld", (long) seekStart);
result = UNKNOWN_ERROR;
goto bail;
}
/* read the last part of the file into the buffer */
if (fread(buf, 1, readAmount, mZipFp) != (size_t) readAmount) {
result = UNKNOWN_ERROR;
goto bail;
}
/* read the last part of the file into the buffer */
if (fread(buf, 1, readAmount, mZipFp) != (size_t) readAmount) {
- LOGD("short file? wanted %ld\n", readAmount);
+
A
LOGD("short file? wanted %ld\n", readAmount);
result = UNKNOWN_ERROR;
goto bail;
}
result = UNKNOWN_ERROR;
goto bail;
}
@@
-253,12
+253,12
@@
status_t ZipFile::readCentralDir(void)
if (buf[i] == 0x50 &&
ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature)
{
if (buf[i] == 0x50 &&
ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature)
{
- LOGV("+++ Found EOCD at buf+%d\n", i);
+
A
LOGV("+++ Found EOCD at buf+%d\n", i);
break;
}
}
if (i < 0) {
break;
}
}
if (i < 0) {
- LOGD("EOCD not found, not Zip\n");
+
A
LOGD("EOCD not found, not Zip\n");
result = INVALID_OPERATION;
goto bail;
}
result = INVALID_OPERATION;
goto bail;
}
@@
-266,7
+266,7
@@
status_t ZipFile::readCentralDir(void)
/* extract eocd values */
result = mEOCD.readBuf(buf + i, readAmount - i);
if (result != NO_ERROR) {
/* extract eocd values */
result = mEOCD.readBuf(buf + i, readAmount - i);
if (result != NO_ERROR) {
- LOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
+
A
LOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
goto bail;
}
//mEOCD.dump();
goto bail;
}
//mEOCD.dump();
@@
-274,7
+274,7
@@
status_t ZipFile::readCentralDir(void)
if (mEOCD.mDiskNumber != 0 || mEOCD.mDiskWithCentralDir != 0 ||
mEOCD.mNumEntries != mEOCD.mTotalNumEntries)
{
if (mEOCD.mDiskNumber != 0 || mEOCD.mDiskWithCentralDir != 0 ||
mEOCD.mNumEntries != mEOCD.mTotalNumEntries)
{
- LOGD("Archive spanning not supported\n");
+
A
LOGD("Archive spanning not supported\n");
result = INVALID_OPERATION;
goto bail;
}
result = INVALID_OPERATION;
goto bail;
}
@@
-294,7
+294,7
@@
status_t ZipFile::readCentralDir(void)
* we're hoping to preserve.
*/
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
* we're hoping to preserve.
*/
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
- LOGD("Failure seeking to central dir offset %ld\n",
+
A
LOGD("Failure seeking to central dir offset %ld\n",
mEOCD.mCentralDirOffset);
result = UNKNOWN_ERROR;
goto bail;
mEOCD.mCentralDirOffset);
result = UNKNOWN_ERROR;
goto bail;
@@
-303,14
+303,14
@@
status_t ZipFile::readCentralDir(void)
/*
* Loop through and read the central dir entries.
*/
/*
* Loop through and read the central dir entries.
*/
- LOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries);
+
A
LOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries);
int entry;
for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
ZipEntry* pEntry = new ZipEntry;
result = pEntry->initFromCDE(mZipFp);
if (result != NO_ERROR) {
int entry;
for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
ZipEntry* pEntry = new ZipEntry;
result = pEntry->initFromCDE(mZipFp);
if (result != NO_ERROR) {
- LOGD("initFromCDE failed\n");
+
A
LOGD("initFromCDE failed\n");
delete pEntry;
goto bail;
}
delete pEntry;
goto bail;
}
@@
-325,16
+325,16
@@
status_t ZipFile::readCentralDir(void)
{
unsigned char checkBuf[4];
if (fread(checkBuf, 1, 4, mZipFp) != 4) {
{
unsigned char checkBuf[4];
if (fread(checkBuf, 1, 4, mZipFp) != 4) {
- LOGD("EOCD check read failed\n");
+
A
LOGD("EOCD check read failed\n");
result = INVALID_OPERATION;
goto bail;
}
if (ZipEntry::getLongLE(checkBuf) != EndOfCentralDir::kSignature) {
result = INVALID_OPERATION;
goto bail;
}
if (ZipEntry::getLongLE(checkBuf) != EndOfCentralDir::kSignature) {
- LOGD("EOCD read check failed\n");
+
A
LOGD("EOCD read check failed\n");
result = UNKNOWN_ERROR;
goto bail;
}
result = UNKNOWN_ERROR;
goto bail;
}
- LOGV("+++ EOCD read check passed\n");
+
A
LOGV("+++ EOCD read check passed\n");
}
bail:
}
bail:
@@
-416,7
+416,7
@@
status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
bool failed = false;
result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
if (result != NO_ERROR) {
bool failed = false;
result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
if (result != NO_ERROR) {
- LOGD("compression failed, storing\n");
+
A
LOGD("compression failed, storing\n");
failed = true;
} else {
/*
failed = true;
} else {
/*
@@
-427,7
+427,7
@@
status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
long src = inputFp ? ftell(inputFp) : size;
long dst = ftell(mZipFp) - startPosn;
if (dst + (dst / 10) > src) {
long src = inputFp ? ftell(inputFp) : size;
long dst = ftell(mZipFp) - startPosn;
if (dst + (dst / 10) > src) {
- LOGD("insufficient compression (src=%ld dst=%ld), storing\n",
+
A
LOGD("insufficient compression (src=%ld dst=%ld), storing\n",
src, dst);
failed = true;
}
src, dst);
failed = true;
}
@@
-449,7
+449,7
@@
status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
}
if (result != NO_ERROR) {
// don't need to truncate; happens in CDE rewrite
}
if (result != NO_ERROR) {
// don't need to truncate; happens in CDE rewrite
- LOGD("failed copying data in\n");
+
A
LOGD("failed copying data in\n");
goto bail;
}
}
goto bail;
}
}
@@
-468,14
+468,14
@@
status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
&compressedLen, &crc);
if (!scanResult || method != ZipEntry::kCompressDeflated) {
scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
&compressedLen, &crc);
if (!scanResult || method != ZipEntry::kCompressDeflated) {
- LOGD("this isn't a deflated gzip file?");
+
A
LOGD("this isn't a deflated gzip file?");
result = UNKNOWN_ERROR;
goto bail;
}
result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
if (result != NO_ERROR) {
result = UNKNOWN_ERROR;
goto bail;
}
result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
if (result != NO_ERROR) {
- LOGD("failed copying gzip data in\n");
+
A
LOGD("failed copying gzip data in\n");
goto bail;
}
} else {
goto bail;
}
} else {
@@
-603,7
+603,7
@@
status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
!= NO_ERROR)
{
if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
!= NO_ERROR)
{
- LOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
+
A
LOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
result = UNKNOWN_ERROR;
goto bail;
}
result = UNKNOWN_ERROR;
goto bail;
}
@@
-660,7
+660,7
@@
status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
*pCRC32 = crc32(*pCRC32, tmpBuf, count);
if (fwrite(tmpBuf, 1, count, dstFp) != count) {
*pCRC32 = crc32(*pCRC32, tmpBuf, count);
if (fwrite(tmpBuf, 1, count, dstFp) != count) {
- LOGD("fwrite %d bytes failed\n", (int) count);
+
A
LOGD("fwrite %d bytes failed\n", (int) count);
return UNKNOWN_ERROR;
}
}
return UNKNOWN_ERROR;
}
}
@@
-682,7
+682,7
@@
status_t ZipFile::copyDataToFp(FILE* dstFp,
if (size > 0) {
*pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);
if (fwrite(data, 1, size, dstFp) != size) {
if (size > 0) {
*pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);
if (fwrite(data, 1, size, dstFp) != size) {
- LOGD("fwrite %d bytes failed\n", (int) size);
+
A
LOGD("fwrite %d bytes failed\n", (int) size);
return UNKNOWN_ERROR;
}
}
return UNKNOWN_ERROR;
}
}
@@
-716,7
+716,7
@@
status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
count = fread(tmpBuf, 1, readSize, srcFp);
if ((long) count != readSize) { // error or unexpected EOF
count = fread(tmpBuf, 1, readSize, srcFp);
if ((long) count != readSize) { // error or unexpected EOF
- LOGD("fread %d bytes failed\n", (int) readSize);
+
A
LOGD("fread %d bytes failed\n", (int) readSize);
return UNKNOWN_ERROR;
}
return UNKNOWN_ERROR;
}
@@
-724,7
+724,7
@@
status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
*pCRC32 = crc32(*pCRC32, tmpBuf, count);
if (fwrite(tmpBuf, 1, count, dstFp) != count) {
*pCRC32 = crc32(*pCRC32, tmpBuf, count);
if (fwrite(tmpBuf, 1, count, dstFp) != count) {
- LOGD("fwrite %d bytes failed\n", (int) count);
+
A
LOGD("fwrite %d bytes failed\n", (int) count);
return UNKNOWN_ERROR;
}
return UNKNOWN_ERROR;
}
@@
-780,10
+780,10
@@
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
if (zerr != Z_OK) {
result = UNKNOWN_ERROR;
if (zerr == Z_VERSION_ERROR) {
if (zerr != Z_OK) {
result = UNKNOWN_ERROR;
if (zerr == Z_VERSION_ERROR) {
- LOGE("Installed zlib is not compatible with linked version (%s)\n",
+
A
LOGE("Installed zlib is not compatible with linked version (%s)\n",
ZLIB_VERSION);
} else {
ZLIB_VERSION);
} else {
- LOGD("Call to deflateInit2 failed (zerr=%d)\n", zerr);
+
A
LOGD("Call to deflateInit2 failed (zerr=%d)\n", zerr);
}
goto bail;
}
}
goto bail;
}
@@
-799,7
+799,7
@@
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
/* only read if the input buffer is empty */
if (zstream.avail_in == 0 && !atEof) {
/* only read if the input buffer is empty */
if (zstream.avail_in == 0 && !atEof) {
- LOGV("+++ reading %d bytes\n", (int)kBufSize);
+
A
LOGV("+++ reading %d bytes\n", (int)kBufSize);
if (data) {
getSize = size > kBufSize ? kBufSize : size;
memcpy(inBuf, data, getSize);
if (data) {
getSize = size > kBufSize ? kBufSize : size;
memcpy(inBuf, data, getSize);
@@
-808,12
+808,12
@@
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
} else {
getSize = fread(inBuf, 1, kBufSize, srcFp);
if (ferror(srcFp)) {
} else {
getSize = fread(inBuf, 1, kBufSize, srcFp);
if (ferror(srcFp)) {
- LOGD("deflate read failed (errno=%d)\n", errno);
+
A
LOGD("deflate read failed (errno=%d)\n", errno);
goto z_bail;
}
}
if (getSize < kBufSize) {
goto z_bail;
}
}
if (getSize < kBufSize) {
- LOGV("+++ got %d bytes, EOF reached\n",
+
A
LOGV("+++ got %d bytes, EOF reached\n",
(int)getSize);
atEof = true;
}
(int)getSize);
atEof = true;
}
@@
-831,7
+831,7
@@
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
zerr = deflate(&zstream, flush);
if (zerr != Z_OK && zerr != Z_STREAM_END) {
zerr = deflate(&zstream, flush);
if (zerr != Z_OK && zerr != Z_STREAM_END) {
- LOGD("zlib deflate call failed (zerr=%d)\n", zerr);
+
A
LOGD("zlib deflate call failed (zerr=%d)\n", zerr);
result = UNKNOWN_ERROR;
goto z_bail;
}
result = UNKNOWN_ERROR;
goto z_bail;
}
@@
-840,11
+840,11
@@
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
if (zstream.avail_out == 0 ||
(zerr == Z_STREAM_END && zstream.avail_out != (uInt) kBufSize))
{
if (zstream.avail_out == 0 ||
(zerr == Z_STREAM_END && zstream.avail_out != (uInt) kBufSize))
{
- LOGV("+++ writing %d bytes\n", (int) (zstream.next_out - outBuf));
+
A
LOGV("+++ writing %d bytes\n", (int) (zstream.next_out - outBuf));
if (fwrite(outBuf, 1, zstream.next_out - outBuf, dstFp) !=
(size_t)(zstream.next_out - outBuf))
{
if (fwrite(outBuf, 1, zstream.next_out - outBuf, dstFp) !=
(size_t)(zstream.next_out - outBuf))
{
- LOGD("write %d failed in deflate\n",
+
A
LOGD("write %d failed in deflate\n",
(int) (zstream.next_out - outBuf));
goto z_bail;
}
(int) (zstream.next_out - outBuf));
goto z_bail;
}
@@
-931,7
+931,7
@@
status_t ZipFile::flush(void)
* of wasted space at the end of the file. Remove it now.
*/
if (ftruncate(fileno(mZipFp), ftell(mZipFp)) != 0) {
* of wasted space at the end of the file. Remove it now.
*/
if (ftruncate(fileno(mZipFp), ftell(mZipFp)) != 0) {
- LOGW("ftruncate failed %ld: %s\n", ftell(mZipFp), strerror(errno));
+
A
LOGW("ftruncate failed %ld: %s\n", ftell(mZipFp), strerror(errno));
// not fatal
}
// not fatal
}
@@
-1019,7
+1019,7
@@
status_t ZipFile::crunchArchive(void)
pEntry->getLFHOffset(), span);
if (result != NO_ERROR) {
/* this is why you use a temp file */
pEntry->getLFHOffset(), span);
if (result != NO_ERROR) {
/* this is why you use a temp file */
- LOGE("error during crunch - archive is toast\n");
+
A
LOGE("error during crunch - archive is toast\n");
return result;
}
return result;
}
@@
-1061,23
+1061,23
@@
status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
getSize = n;
if (fseek(fp, (long) src, SEEK_SET) != 0) {
getSize = n;
if (fseek(fp, (long) src, SEEK_SET) != 0) {
- LOGD("filemove src seek %ld failed\n", (long) src);
+
A
LOGD("filemove src seek %ld failed\n", (long) src);
return UNKNOWN_ERROR;
}
if (fread(readBuf, 1, getSize, fp) != getSize) {
return UNKNOWN_ERROR;
}
if (fread(readBuf, 1, getSize, fp) != getSize) {
- LOGD("filemove read %ld off=%ld failed\n",
+
A
LOGD("filemove read %ld off=%ld failed\n",
(long) getSize, (long) src);
return UNKNOWN_ERROR;
}
if (fseek(fp, (long) dst, SEEK_SET) != 0) {
(long) getSize, (long) src);
return UNKNOWN_ERROR;
}
if (fseek(fp, (long) dst, SEEK_SET) != 0) {
- LOGD("filemove dst seek %ld failed\n", (long) dst);
+
A
LOGD("filemove dst seek %ld failed\n", (long) dst);
return UNKNOWN_ERROR;
}
if (fwrite(readBuf, 1, getSize, fp) != getSize) {
return UNKNOWN_ERROR;
}
if (fwrite(readBuf, 1, getSize, fp) != getSize) {
- LOGD("filemove write %ld off=%ld failed\n",
+
A
LOGD("filemove write %ld off=%ld failed\n",
(long) getSize, (long) dst);
return UNKNOWN_ERROR;
}
(long) getSize, (long) dst);
return UNKNOWN_ERROR;
}
@@
-1104,7
+1104,7
@@
time_t ZipFile::getModTime(int fd)
struct stat sb;
if (fstat(fd, &sb) < 0) {
struct stat sb;
if (fstat(fd, &sb) < 0) {
- LOGD("HEY: fstat on fd %d failed\n", fd);
+
A
LOGD("HEY: fstat on fd %d failed\n", fd);
return (time_t) -1;
}
return (time_t) -1;
}
@@
-1129,7
+1129,7
@@
int ZipFile::getZipFd(void) const
int fd;
fd = dup(fileno(mZipFp));
if (fd < 0) {
int fd;
fd = dup(fileno(mZipFp));
if (fd < 0) {
- LOGD("didn't work, errno=%d\n", errno);
+
A
LOGD("didn't work, errno=%d\n", errno);
}
return fd;
}
return fd;
@@
-1224,7
+1224,7
@@
status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
if (len < kEOCDLen) {
/* looks like ZIP file got truncated */
if (len < kEOCDLen) {
/* looks like ZIP file got truncated */
- LOGD(" Zip EOCD: expected >= %d bytes, found %d\n",
+
A
LOGD(" Zip EOCD: expected >= %d bytes, found %d\n",
kEOCDLen, len);
return INVALID_OPERATION;
}
kEOCDLen, len);
return INVALID_OPERATION;
}
@@
-1245,7
+1245,7
@@
status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
if (mCommentLen > 0) {
if (kEOCDLen + mCommentLen > len) {
if (mCommentLen > 0) {
if (kEOCDLen + mCommentLen > len) {
- LOGD("EOCD(%d) + comment(%d) exceeds len (%d)\n",
+
A
LOGD("EOCD(%d) + comment(%d) exceeds len (%d)\n",
kEOCDLen, mCommentLen, len);
return UNKNOWN_ERROR;
}
kEOCDLen, mCommentLen, len);
return UNKNOWN_ERROR;
}
@@
-1288,10
+1288,10
@@
status_t ZipFile::EndOfCentralDir::write(FILE* fp)
*/
void ZipFile::EndOfCentralDir::dump(void) const
{
*/
void ZipFile::EndOfCentralDir::dump(void) const
{
- LOGD(" EndOfCentralDir contents:\n");
- LOGD(" diskNum=%u diskWCD=%u numEnt=%u totalNumEnt=%u\n",
+
A
LOGD(" EndOfCentralDir contents:\n");
+
A
LOGD(" diskNum=%u diskWCD=%u numEnt=%u totalNumEnt=%u\n",
mDiskNumber, mDiskWithCentralDir, mNumEntries, mTotalNumEntries);
mDiskNumber, mDiskWithCentralDir, mNumEntries, mTotalNumEntries);
- LOGD(" centDirSize=%lu centDirOff=%lu commentLen=%u\n",
+
A
LOGD(" centDirSize=%lu centDirOff=%lu commentLen=%u\n",
mCentralDirSize, mCentralDirOffset, mCommentLen);
}
mCentralDirSize, mCentralDirOffset, mCommentLen);
}