MCPcopy Create free account
hub / github.com/CyanogenMod/android_frameworks_base / doAdd

Function doAdd

tools/aapt/Command.cpp:1753–1816  ·  view source on GitHub ↗

* Handle the "add" command, which wants to add files to a new or * pre-existing archive. */

Source from the content-addressed store, hash-verified

1751 * pre-existing archive.
1752 */
1753int doAdd(Bundle* bundle)
1754{
1755 ZipFile* zip = NULL;
1756 status_t result = UNKNOWN_ERROR;
1757 const char* zipFileName;
1758
1759 if (bundle->getUpdate()) {
1760 /* avoid confusion */
1761 fprintf(stderr, "ERROR: can't use '-u' with add\n");
1762 goto bail;
1763 }
1764
1765 if (bundle->getFileSpecCount() < 1) {
1766 fprintf(stderr, "ERROR: must specify zip file name\n");
1767 goto bail;
1768 }
1769 zipFileName = bundle->getFileSpecEntry(0);
1770
1771 if (bundle->getFileSpecCount() < 2) {
1772 fprintf(stderr, "NOTE: nothing to do\n");
1773 goto bail;
1774 }
1775
1776 zip = openReadWrite(zipFileName, true);
1777 if (zip == NULL) {
1778 fprintf(stderr, "ERROR: failed opening/creating '%s' as Zip file\n", zipFileName);
1779 goto bail;
1780 }
1781
1782 for (int i = 1; i < bundle->getFileSpecCount(); i++) {
1783 const char* fileName = bundle->getFileSpecEntry(i);
1784
1785 if (strcasecmp(String8(fileName).getPathExtension().string(), ".gz") == 0) {
1786 printf(" '%s'... (from gzip)\n", fileName);
1787 result = zip->addGzip(fileName, String8(fileName).getBasePath().string(), NULL);
1788 } else {
1789 if (bundle->getJunkPath()) {
1790 String8 storageName = String8(fileName).getPathLeaf();
1791 printf(" '%s' as '%s'...\n", fileName, storageName.string());
1792 result = zip->add(fileName, storageName.string(),
1793 bundle->getCompressionMethod(), NULL);
1794 } else {
1795 printf(" '%s'...\n", fileName);
1796 result = zip->add(fileName, bundle->getCompressionMethod(), NULL);
1797 }
1798 }
1799 if (result != NO_ERROR) {
1800 fprintf(stderr, "Unable to add '%s' to '%s'", bundle->getFileSpecEntry(i), zipFileName);
1801 if (result == NAME_NOT_FOUND)
1802 fprintf(stderr, ": file not found\n");
1803 else if (result == ALREADY_EXISTS)
1804 fprintf(stderr, ": already exists in archive\n");
1805 else
1806 fprintf(stderr, "\n");
1807 goto bail;
1808 }
1809 }
1810

Callers 1

handleCommandFunction · 0.70

Calls 9

openReadWriteFunction · 0.85
getUpdateMethod · 0.80
getFileSpecCountMethod · 0.80
getFileSpecEntryMethod · 0.80
stringMethod · 0.80
addGzipMethod · 0.80
getJunkPathMethod · 0.80
addMethod · 0.65
getCompressionMethodMethod · 0.45

Tested by

no test coverage detected