* Process a regular file, adding it to the archive if appropriate. * * If we're in "update" mode, and the file already exists in the archive, * delete the existing entry before adding the new one. */
| 430 | * delete the existing entry before adding the new one. |
| 431 | */ |
| 432 | bool processFile(Bundle* bundle, ZipFile* zip, |
| 433 | const sp<AaptGroup>& group, const sp<AaptFile>& file) |
| 434 | { |
| 435 | const bool hasData = file->hasData(); |
| 436 | |
| 437 | String8 storageName(group->getPath()); |
| 438 | storageName.convertToResPath(); |
| 439 | ZipEntry* entry; |
| 440 | bool fromGzip = false; |
| 441 | status_t result; |
| 442 | |
| 443 | /* |
| 444 | * See if the filename ends in ".EXCLUDE". We can't use |
| 445 | * String8::getPathExtension() because the length of what it considers |
| 446 | * to be an extension is capped. |
| 447 | * |
| 448 | * The Asset Manager doesn't check for ".EXCLUDE" in Zip archives, |
| 449 | * so there's no value in adding them (and it makes life easier on |
| 450 | * the AssetManager lib if we don't). |
| 451 | * |
| 452 | * NOTE: this restriction has been removed. If you're in this code, you |
| 453 | * should clean this up, but I'm in here getting rid of Path Name, and I |
| 454 | * don't want to make other potentially breaking changes --joeo |
| 455 | */ |
| 456 | int fileNameLen = storageName.length(); |
| 457 | int excludeExtensionLen = strlen(kExcludeExtension); |
| 458 | if (fileNameLen > excludeExtensionLen |
| 459 | && (0 == strcmp(storageName.string() + (fileNameLen - excludeExtensionLen), |
| 460 | kExcludeExtension))) { |
| 461 | fprintf(stderr, "warning: '%s' not added to Zip\n", storageName.string()); |
| 462 | return true; |
| 463 | } |
| 464 | |
| 465 | if (strcasecmp(storageName.getPathExtension().string(), ".gz") == 0) { |
| 466 | fromGzip = true; |
| 467 | storageName = storageName.getBasePath(); |
| 468 | } |
| 469 | |
| 470 | if (bundle->getUpdate()) { |
| 471 | entry = zip->getEntryByName(storageName.string()); |
| 472 | if (entry != NULL) { |
| 473 | /* file already exists in archive; there can be only one */ |
| 474 | if (entry->getMarked()) { |
| 475 | fprintf(stderr, |
| 476 | "ERROR: '%s' exists twice (check for with & w/o '.gz'?)\n", |
| 477 | file->getPrintableSource().string()); |
| 478 | return false; |
| 479 | } |
| 480 | if (!hasData) { |
| 481 | const String8& srcName = file->getSourceFile(); |
| 482 | time_t fileModWhen; |
| 483 | fileModWhen = getFileModDate(srcName.string()); |
| 484 | if (fileModWhen == (time_t) -1) { // file existence tested earlier, |
| 485 | return false; // not expecting an error here |
| 486 | } |
| 487 | |
| 488 | if (fileModWhen > entry->getModWhen()) { |
| 489 | // mark as deleted so add() will succeed |
no test coverage detected