From cf6da173f62ee96703714e66f8538069a46a63e3 Mon Sep 17 00:00:00 2001 From: Judd Vinet Date: Thu, 28 Sep 2006 20:51:33 +0000 Subject: removed libtar support in favour of libarchive --- lib/libalpm/package.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'lib/libalpm/package.c') diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 277b3946..c8822240 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -26,8 +26,6 @@ #include #include #include -#include -#include /* pacman */ #include "log.h" #include "util.h" @@ -247,14 +245,9 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile) int config = 0; int filelist = 0; int scriptcheck = 0; - TAR *tar = NULL; + register struct archive *archive; + struct archive_entry *entry; pmpkg_t *info = NULL; - tartype_t gztype = { - (openfunc_t)_alpm_gzopen_frontend, - (closefunc_t)gzclose, - (readfunc_t)gzread, - (writefunc_t)gzwrite - }; if(pkgfile == NULL || strlen(pkgfile) == 0) { RET_ERR(PM_ERR_WRONG_ARGS, NULL); @@ -269,23 +262,30 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile) goto error; } - if(tar_open(&tar, pkgfile, &gztype, O_RDONLY, 0, TAR_GNU) == -1) { + if((archive = archive_read_new()) == NULL) { + RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL); + } + + archive_read_support_compression_all(archive); + archive_read_support_format_all(archive); + if(archive_read_open_file(archive, pkgfile, 10240) != ARCHIVE_OK) { pm_errno = PM_ERR_NOT_A_FILE; goto error; } - for(i = 0; !th_read(tar); i++) { + for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) { if(config && filelist && scriptcheck) { /* we have everything we need */ break; } - if(!strcmp(th_get_pathname(tar), ".PKGINFO")) { + if(!strcmp(archive_entry_pathname(entry), ".PKGINFO")) { char *descfile; int fd; /* extract this file into /tmp. it has info for us */ descfile = strdup("/tmp/alpm_XXXXXX"); fd = mkstemp(descfile); - tar_extract_file(tar, descfile); + _alpm_archive_read_entry_data_into_fd(archive, fd); + close(fd); /* parse the info file */ if(parse_descfile(descfile, info, 0) == -1) { _alpm_log(PM_LOG_ERROR, _("could not parse the package description file")); @@ -300,10 +300,10 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile) FREE(descfile); close(fd); continue; - } else if(!strcmp(th_get_pathname(tar), "._install") || !strcmp(th_get_pathname(tar), ".INSTALL")) { + } else if(!strcmp(archive_entry_pathname(entry), "._install") || !strcmp(archive_entry_pathname(entry), ".INSTALL")) { info->scriptlet = 1; scriptcheck = 1; - } else if(!strcmp(th_get_pathname(tar), ".FILELIST")) { + } else if(!strcmp(archive_entry_pathname(entry), ".FILELIST")) { /* Build info->files from the filelist */ FILE *fp; char *fn; @@ -316,7 +316,8 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile) } fn = strdup("/tmp/alpm_XXXXXX"); fd = mkstemp(fn); - tar_extract_file(tar, fn); + _alpm_archive_read_entry_data_into_fd(archive, fd); + close(fd); fp = fopen(fn, "r"); while(!feof(fp)) { if(fgets(str, PATH_MAX, fp) == NULL) { @@ -339,19 +340,18 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile) if(!filelist) { /* no .FILELIST present in this package.. build the filelist the */ /* old-fashioned way, one at a time */ - expath = strdup(th_get_pathname(tar)); + expath = strdup(archive_entry_pathname(entry)); info->files = _alpm_list_add(info->files, expath); } } - if(TH_ISREG(tar) && tar_skip_regfile(tar)) { + if(archive_read_data_skip(archive)) { _alpm_log(PM_LOG_ERROR, _("bad package file in %s"), pkgfile); goto error; } expath = NULL; } - tar_close(tar); - tar = NULL; + archive_read_finish(archive); if(!config) { _alpm_log(PM_LOG_ERROR, _("missing package info file in %s"), pkgfile); @@ -367,9 +367,7 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile) error: FREEPKG(info); - if(tar) { - tar_close(tar); - } + archive_read_finish(archive); return(NULL); } -- cgit v1.2.3-54-g00ecf