* Delete files from an existing archive. */
| 1820 | * Delete files from an existing archive. |
| 1821 | */ |
| 1822 | int doRemove(Bundle* bundle) |
| 1823 | { |
| 1824 | ZipFile* zip = NULL; |
| 1825 | status_t result = UNKNOWN_ERROR; |
| 1826 | const char* zipFileName; |
| 1827 | |
| 1828 | if (bundle->getFileSpecCount() < 1) { |
| 1829 | fprintf(stderr, "ERROR: must specify zip file name\n"); |
| 1830 | goto bail; |
| 1831 | } |
| 1832 | zipFileName = bundle->getFileSpecEntry(0); |
| 1833 | |
| 1834 | if (bundle->getFileSpecCount() < 2) { |
| 1835 | fprintf(stderr, "NOTE: nothing to do\n"); |
| 1836 | goto bail; |
| 1837 | } |
| 1838 | |
| 1839 | zip = openReadWrite(zipFileName, false); |
| 1840 | if (zip == NULL) { |
| 1841 | fprintf(stderr, "ERROR: failed opening Zip archive '%s'\n", |
| 1842 | zipFileName); |
| 1843 | goto bail; |
| 1844 | } |
| 1845 | |
| 1846 | for (int i = 1; i < bundle->getFileSpecCount(); i++) { |
| 1847 | const char* fileName = bundle->getFileSpecEntry(i); |
| 1848 | ZipEntry* entry; |
| 1849 | |
| 1850 | entry = zip->getEntryByName(fileName); |
| 1851 | if (entry == NULL) { |
| 1852 | printf(" '%s' NOT FOUND\n", fileName); |
| 1853 | continue; |
| 1854 | } |
| 1855 | |
| 1856 | result = zip->remove(entry); |
| 1857 | |
| 1858 | if (result != NO_ERROR) { |
| 1859 | fprintf(stderr, "Unable to delete '%s' from '%s'\n", |
| 1860 | bundle->getFileSpecEntry(i), zipFileName); |
| 1861 | goto bail; |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | /* update the archive */ |
| 1866 | zip->flush(); |
| 1867 | |
| 1868 | bail: |
| 1869 | delete zip; |
| 1870 | return (result != NO_ERROR); |
| 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | /* |
no test coverage detected