add check mode to zipalign
Add a -c flag to zipalign to do nothing but check the input zip file
for alignment (with or without verbosity).
diff --git a/tools/zipalign/ZipAlign.cpp b/tools/zipalign/ZipAlign.cpp
index 9e3cb66..058f9ed 100644
--- a/tools/zipalign/ZipAlign.cpp
+++ b/tools/zipalign/ZipAlign.cpp
@@ -30,7 +30,8 @@
{
fprintf(stderr, "Zip alignment utility\n");
fprintf(stderr,
- "Usage: zipalign [-f] [-v] <align> infile.zip outfile.zip\n");
+ "Usage: zipalign [-f] [-v] <align> infile.zip outfile.zip\n"
+ " zipalign -c [-v] <align> infile.zip\n" );
}
/*
@@ -152,14 +153,14 @@
pEntry = zipFile.getEntryByIndex(i);
if (pEntry->isCompressed()) {
if (verbose) {
- printf("%8ld %s (OK - compressed)\n",
+ printf("%8ld %s (OK - compressed)\n",
(long) pEntry->getFileOffset(), pEntry->getFileName());
}
} else {
long offset = pEntry->getFileOffset();
if ((offset % alignment) != 0) {
if (verbose) {
- printf("%8ld %s (BAD - %ld)\n",
+ printf("%8ld %s (BAD - %ld)\n",
(long) offset, pEntry->getFileName(),
offset % alignment);
}
@@ -185,6 +186,7 @@
int main(int argc, char* const argv[])
{
bool wantUsage = false;
+ bool check = false;
bool force = false;
bool verbose = false;
int result = 1;
@@ -204,6 +206,9 @@
while (*cp != '\0') {
switch (*cp) {
+ case 'c':
+ check = true;
+ break;
case 'f':
force = true;
break;
@@ -223,7 +228,7 @@
argv++;
}
- if (argc != 3) {
+ if (!((check && argc == 2) || (!check && argc == 3))) {
wantUsage = true;
goto bail;
}
@@ -235,12 +240,17 @@
goto bail;
}
- /* create the new archive */
- result = process(argv[1], argv[2], alignment, force);
+ if (check) {
+ /* check existing archive for correct alignment */
+ result = verify(argv[1], alignment, verbose);
+ } else {
+ /* create the new archive */
+ result = process(argv[1], argv[2], alignment, force);
- /* trust, but verify */
- if (result == 0)
- result = verify(argv[2], alignment, verbose);
+ /* trust, but verify */
+ if (result == 0)
+ result = verify(argv[2], alignment, verbose);
+ }
bail:
if (wantUsage) {
@@ -250,4 +260,3 @@
return result;
}
-