void EnableArchiveFormats(struct archive *p_archive) { // archive_read_support_filter_bzip2(p_archive); // archive_read_support_filter_compress(p_archive); // archive_read_support_filter_gzip(p_archive); // archive_read_support_filter_grzip(p_archive); // archive_read_support_filter_lrzip(p_archive); // archive_read_support_filter_lzip(p_archive); archive_read_support_filter_lzma(p_archive); archive_read_support_filter_lzop(p_archive); archive_read_support_filter_none(p_archive); archive_read_support_filter_rpm(p_archive); archive_read_support_filter_uu(p_archive); archive_read_support_filter_xz(p_archive); // archive_read_support_format_7zip(p_archive); archive_read_support_format_ar(p_archive); archive_read_support_format_cab(p_archive); archive_read_support_format_cpio(p_archive); archive_read_support_format_gnutar(p_archive); // archive_read_support_format_iso9660(p_archive); archive_read_support_format_lha(p_archive); archive_read_support_format_mtree(p_archive); archive_read_support_format_rar(p_archive); archive_read_support_format_raw(p_archive); archive_read_support_format_tar(p_archive); archive_read_support_format_xar(p_archive); // archive_read_support_format_zip(p_archive); }
static int get_format(const char *archive) { struct archive *a; struct archive_entry *ae; int found_format; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_mtree(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_empty(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, strlen(archive))); // Read one header to settle the format. // This might return EOF or OK. archive_read_next_header(a, &ae); found_format = archive_format(a); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); return found_format; }
int archive_read_support_format_all(struct archive *a) { archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_all"); /* TODO: It would be nice to compute the ordering * here automatically so that people who enable just * a few formats can still get the benefits. That * may just require the format registration to include * a "maximum read-ahead" value (anything that uses seek * would be essentially infinite read-ahead). The core * bid management can then sort the bidders before calling * them. * * If you implement the above, please return the list below * to alphabetic order. */ /* * These bidders are all pretty cheap; they just examine a * small initial part of the archive. If one of these bids * high, we can maybe avoid running any of the more expensive * bidders below. */ archive_read_support_format_ar(a); archive_read_support_format_cpio(a); archive_read_support_format_empty(a); archive_read_support_format_lha(a); archive_read_support_format_mtree(a); archive_read_support_format_tar(a); archive_read_support_format_xar(a); /* * Install expensive bidders last. By doing them last, we * increase the chance that a high bid from someone else will * make it unnecessary for these to do anything at all. */ /* These three have potentially large look-ahead. */ archive_read_support_format_7zip(a); archive_read_support_format_cab(a); archive_read_support_format_rar(a); archive_read_support_format_iso9660(a); /* Seek is really bad, since it forces the read-ahead * logic to discard buffered data. */ archive_read_support_format_zip(a); /* Note: We always return ARCHIVE_OK here, even if some of the * above return ARCHIVE_WARN. The intent here is to enable * "as much as possible." Clients who need specific * compression should enable those individually so they can * verify the level of support. */ /* Clear any warning messages set by the above functions. */ archive_clear_error(a); return (ARCHIVE_OK); }
int archive_read_support_format_all(struct archive *a) { archive_read_support_format_ar(a); archive_read_support_format_cpio(a); archive_read_support_format_empty(a); archive_read_support_format_iso9660(a); archive_read_support_format_mtree(a); archive_read_support_format_tar(a); archive_read_support_format_xar(a); archive_read_support_format_zip(a); return (ARCHIVE_OK); }
int do_extract_mtree(char *mtree, const char *prefix) { struct archive *a = NULL; struct archive_entry *ae; char path[MAXPATHLEN]; const char *fpath; int retcode = EPKG_OK; int ret; if (mtree == NULL || *mtree == '\0') return EPKG_OK; a = archive_read_new(); archive_read_support_filter_none(a); archive_read_support_format_mtree(a); if (archive_read_open_memory(a, mtree, strlen(mtree)) != ARCHIVE_OK) { pkg_emit_error("Fail to extract the mtree: %s", archive_error_string(a)); retcode = EPKG_FATAL; goto cleanup; } while ((ret = archive_read_next_header(a, &ae)) != ARCHIVE_EOF) { if (ret != ARCHIVE_OK) { pkg_emit_error("Skipping unsupported mtree line: %s", archive_error_string(a)); continue; } fpath = archive_entry_pathname(ae); if (*fpath != '/') { snprintf(path, sizeof(path), "%s/%s", prefix, fpath); archive_entry_set_pathname(ae, path); } /* Ignored failed extraction on purpose */ archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS); } cleanup: if (a != NULL) archive_read_free(a); return (retcode); }
int archive_read_support_format_by_code(struct archive *a, int format_code) { archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_by_code"); switch (format_code & ARCHIVE_FORMAT_BASE_MASK) { case ARCHIVE_FORMAT_7ZIP: return archive_read_support_format_7zip(a); break; case ARCHIVE_FORMAT_AR: return archive_read_support_format_ar(a); break; case ARCHIVE_FORMAT_CAB: return archive_read_support_format_cab(a); break; case ARCHIVE_FORMAT_CPIO: return archive_read_support_format_cpio(a); break; case ARCHIVE_FORMAT_ISO9660: return archive_read_support_format_iso9660(a); break; case ARCHIVE_FORMAT_LHA: return archive_read_support_format_lha(a); break; case ARCHIVE_FORMAT_MTREE: return archive_read_support_format_mtree(a); break; case ARCHIVE_FORMAT_RAR: return archive_read_support_format_rar(a); break; case ARCHIVE_FORMAT_TAR: return archive_read_support_format_tar(a); break; case ARCHIVE_FORMAT_XAR: return archive_read_support_format_xar(a); break; case ARCHIVE_FORMAT_ZIP: return archive_read_support_format_zip(a); break; } return (ARCHIVE_FATAL); }
/** * Open a package mtree file for reading. * @param pkg the local package to read the changelog of * @return a archive structure for the package mtree file */ static struct archive *_cache_mtree_open(alpm_pkg_t *pkg) { int r; struct archive *mtree; alpm_db_t *db = alpm_pkg_get_db(pkg); char *mtfile = _alpm_local_db_pkgpath(db, pkg, "mtree"); if(access(mtfile, F_OK) != 0) { /* there is no mtree file for this package */ goto error; } if((mtree = archive_read_new()) == NULL) { pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE; goto error; } _alpm_archive_read_support_filter_all(mtree); archive_read_support_format_mtree(mtree); if((r = _alpm_archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) { _alpm_log(pkg->handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"), mtfile, archive_error_string(mtree)); pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE; _alpm_archive_read_free(mtree); goto error; } free(mtfile); return mtree; error: free(mtfile); return NULL; }