2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-17 20:47:03 +05:30
|
|
|
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-02-24 04:54:11 +05:30
|
|
|
#include <sys/stat.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2011-02-24 04:54:11 +05:30
|
|
|
#include <unistd.h>
|
2011-12-24 16:37:30 +05:30
|
|
|
#include <libgen.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-07-28 19:55:01 +05:30
|
|
|
static int
|
|
|
|
set_extract_flags(void)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-07-28 19:55:01 +05:30
|
|
|
int flags;
|
2010-01-28 20:51:08 +05:30
|
|
|
|
2011-07-28 19:55:01 +05:30
|
|
|
if (geteuid() == 0)
|
|
|
|
flags = FEXTRACT_FLAGS;
|
2009-08-17 22:37:20 +05:30
|
|
|
else
|
2011-07-28 19:55:01 +05:30
|
|
|
flags = EXTRACT_FLAGS;
|
2010-01-28 20:51:08 +05:30
|
|
|
|
2011-07-28 19:55:01 +05:30
|
|
|
return flags;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2011-01-21 21:46:58 +05:30
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
extract_metafile(struct xbps_handle *xhp,
|
|
|
|
struct archive *ar,
|
2011-01-21 21:46:58 +05:30
|
|
|
struct archive_entry *entry,
|
|
|
|
const char *file,
|
2011-11-24 15:53:08 +05:30
|
|
|
const char *pkgver,
|
2011-01-21 21:46:58 +05:30
|
|
|
bool exec,
|
|
|
|
int flags)
|
|
|
|
{
|
2011-11-24 15:53:08 +05:30
|
|
|
const char *version;
|
2011-12-24 16:37:30 +05:30
|
|
|
char *buf, *dirc, *dname, *pkgname;
|
2011-01-21 21:46:58 +05:30
|
|
|
int rv;
|
|
|
|
|
2011-11-24 15:53:08 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
if (pkgname == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
version = xbps_pkg_version(pkgver);
|
2011-12-24 16:37:30 +05:30
|
|
|
if (version == NULL) {
|
|
|
|
free(pkgname);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2011-12-15 15:49:20 +05:30
|
|
|
buf = xbps_xasprintf("%s/metadata/%s/%s",
|
2011-01-21 21:46:58 +05:30
|
|
|
XBPS_META_PATH, pkgname, file);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
free(pkgname);
|
2011-01-21 21:46:58 +05:30
|
|
|
return ENOMEM;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
archive_entry_set_pathname(entry, buf);
|
2011-12-24 16:37:30 +05:30
|
|
|
dirc = strdup(buf);
|
|
|
|
if (dirc == NULL) {
|
|
|
|
free(buf);
|
|
|
|
free(pkgname);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
free(buf);
|
2011-12-24 16:37:30 +05:30
|
|
|
dname = dirname(dirc);
|
|
|
|
if (access(dname, X_OK) == -1) {
|
|
|
|
if (xbps_mkpath(dname, 0755) == -1) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-12-24 16:37:30 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] failed to create metadir `%s': %s",
|
|
|
|
pkgver, dname, strerror(errno));
|
|
|
|
free(dirc);
|
|
|
|
free(pkgname);
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
if (exec)
|
|
|
|
archive_entry_set_perm(entry, 0750);
|
|
|
|
|
|
|
|
if (archive_read_extract(ar, entry, flags) != 0) {
|
2011-11-24 15:53:08 +05:30
|
|
|
rv = archive_errno(ar);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [unpack] failed to extract metafile `%s': %s",
|
|
|
|
pkgver, file, strerror(rv));
|
2012-01-20 15:40:52 +05:30
|
|
|
free(dirc);
|
2011-11-24 15:53:08 +05:30
|
|
|
free(pkgname);
|
|
|
|
return rv;
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2011-11-24 15:53:08 +05:30
|
|
|
free(pkgname);
|
2012-01-20 15:40:52 +05:30
|
|
|
free(dirc);
|
2011-01-21 21:46:58 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
remove_metafile(struct xbps_handle *xhp,
|
|
|
|
const char *file,
|
|
|
|
const char *pkgver)
|
2011-01-21 21:46:58 +05:30
|
|
|
{
|
2011-11-24 15:53:08 +05:30
|
|
|
const char *version;
|
|
|
|
char *buf, *pkgname;
|
|
|
|
|
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
if (pkgname == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
version = xbps_pkg_version(pkgver);
|
2011-12-24 16:37:30 +05:30
|
|
|
if (version == NULL) {
|
|
|
|
free(pkgname);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
2011-12-15 15:49:20 +05:30
|
|
|
buf = xbps_xasprintf("%s/metadata/%s/%s",
|
2011-03-04 15:18:39 +05:30
|
|
|
XBPS_META_PATH, pkgname, file);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
free(pkgname);
|
2011-01-21 21:46:58 +05:30
|
|
|
return ENOMEM;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
if (unlink(buf) == -1) {
|
|
|
|
if (errno && errno != ENOENT) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] failed to remove metafile `%s': %s",
|
|
|
|
pkgver, file, strerror(errno));
|
|
|
|
free(pkgname);
|
2011-01-21 21:46:58 +05:30
|
|
|
free(buf);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(buf);
|
2011-11-24 15:53:08 +05:30
|
|
|
free(pkgname);
|
2011-01-21 21:46:58 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-26 13:57:24 +05:30
|
|
|
static const char *
|
|
|
|
find_pkg_symlink_target(prop_dictionary_t d, const char *file)
|
|
|
|
{
|
|
|
|
prop_array_t links;
|
|
|
|
prop_object_t obj;
|
|
|
|
size_t i;
|
|
|
|
const char *pkgfile, *tgt = NULL;
|
|
|
|
char *rfile;
|
|
|
|
|
|
|
|
assert(d);
|
|
|
|
|
|
|
|
links = prop_dictionary_get(d, "links");
|
|
|
|
assert(links);
|
|
|
|
|
|
|
|
for (i = 0; i < prop_array_count(links); i++) {
|
|
|
|
rfile = strchr(file, '.') + 1;
|
|
|
|
obj = prop_array_get(links, i);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "file", &pkgfile);
|
|
|
|
if (strcmp(rfile, pkgfile) == 0) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "target", &tgt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tgt;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
unpack_archive(struct xbps_handle *xhp,
|
|
|
|
prop_dictionary_t pkg_repod,
|
|
|
|
struct archive *ar)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-02-03 22:19:43 +05:30
|
|
|
prop_dictionary_t propsd = NULL, filesd = NULL, old_filesd = NULL;
|
2012-10-24 11:15:00 +05:30
|
|
|
prop_array_t array, obsoletes;
|
|
|
|
prop_object_t obj;
|
2011-08-01 16:05:47 +05:30
|
|
|
const struct stat *entry_statp;
|
2012-03-07 16:30:08 +05:30
|
|
|
struct stat st;
|
2012-08-31 13:44:33 +05:30
|
|
|
struct xbps_unpack_cb_data xucd;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct archive_entry *entry;
|
2012-10-24 11:15:00 +05:30
|
|
|
size_t i, entry_idx = 0;
|
|
|
|
const char *file, *entry_pname, *transact, *pkgname;
|
2012-10-26 13:57:24 +05:30
|
|
|
const char *version, *pkgver, *fname, *tgtlnk;
|
|
|
|
char *buf, *buf2, *p, *p2, *pkgfilesd = NULL, *pkgpropsd = NULL;
|
|
|
|
int ar_rv, rv, rv_stat, flags;
|
2012-02-21 00:53:33 +05:30
|
|
|
bool preserve, update, conf_file, file_exists, skip_obsoletes;
|
2012-10-26 13:57:24 +05:30
|
|
|
bool softreplace, skip_extract;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
2009-08-17 22:37:20 +05:30
|
|
|
assert(ar != NULL);
|
2009-12-02 11:01:03 +05:30
|
|
|
|
2012-05-26 02:14:58 +05:30
|
|
|
preserve = update = conf_file = file_exists = false;
|
|
|
|
skip_obsoletes = softreplace = false;
|
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
prop_dictionary_get_bool(pkg_repod, "preserve", &preserve);
|
2012-02-21 00:53:33 +05:30
|
|
|
prop_dictionary_get_bool(pkg_repod, "skip-obsoletes", &skip_obsoletes);
|
2012-05-26 02:14:58 +05:30
|
|
|
prop_dictionary_get_bool(pkg_repod, "softreplace", &softreplace);
|
2011-01-20 07:25:40 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod,
|
2011-02-05 16:51:04 +05:30
|
|
|
"transaction", &transact);
|
2011-11-24 15:53:08 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname);
|
|
|
|
|
|
|
|
if (xhp->unpack_cb != NULL) {
|
|
|
|
/* initialize data for unpack cb */
|
2012-08-31 13:44:33 +05:30
|
|
|
memset(&xucd, 0, sizeof(xucd));
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
if (access(xhp->rootdir, R_OK) == -1) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (xbps_mkpath(xhp->rootdir, 0750) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2011-12-15 15:49:20 +05:30
|
|
|
if (chdir(xhp->rootdir) == -1) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] failed to chdir to rootdir `%s': %s",
|
2011-12-15 15:49:20 +05:30
|
|
|
pkgver, xhp->rootdir, strerror(errno));
|
2011-11-24 15:53:08 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
if (strcmp(transact, "update") == 0)
|
2009-12-09 20:44:35 +05:30
|
|
|
update = true;
|
2010-01-19 00:19:32 +05:30
|
|
|
/*
|
2012-06-04 17:44:46 +05:30
|
|
|
* Always remove current INSTALL/REMOVE scripts in pkg's metadir,
|
|
|
|
* as security measures.
|
2010-01-19 00:19:32 +05:30
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = remove_metafile(xhp, "INSTALL", pkgver)) != 0)
|
2012-06-04 17:44:46 +05:30
|
|
|
goto out;
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = remove_metafile(xhp, "REMOVE", pkgver)) != 0)
|
2012-06-04 17:44:46 +05:30
|
|
|
goto out;
|
|
|
|
|
2010-01-23 04:26:39 +05:30
|
|
|
/*
|
|
|
|
* Process the archive files.
|
|
|
|
*/
|
2012-06-05 20:16:50 +05:30
|
|
|
for (;;) {
|
|
|
|
ar_rv = archive_read_next_header(ar, &entry);
|
|
|
|
if (ar_rv == ARCHIVE_EOF || ar_rv == ARCHIVE_FATAL)
|
|
|
|
break;
|
|
|
|
else if (ar_rv == ARCHIVE_RETRY)
|
|
|
|
continue;
|
|
|
|
|
2012-10-26 13:57:24 +05:30
|
|
|
skip_extract = false;
|
2011-08-01 16:05:47 +05:30
|
|
|
entry_statp = archive_entry_stat(entry);
|
2011-01-20 07:25:40 +05:30
|
|
|
entry_pname = archive_entry_pathname(entry);
|
2011-07-28 19:55:01 +05:30
|
|
|
flags = set_extract_flags();
|
2011-11-10 01:31:25 +05:30
|
|
|
/*
|
|
|
|
* Ignore directories from archive.
|
|
|
|
*/
|
|
|
|
if (S_ISDIR(entry_statp->st_mode)) {
|
|
|
|
archive_read_data_skip(ar);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Prepare unpack callback ops.
|
|
|
|
*/
|
2012-08-31 13:44:33 +05:30
|
|
|
if (xhp->unpack_cb != NULL) {
|
|
|
|
xucd.pkgver = pkgver;
|
|
|
|
xucd.entry = entry_pname;
|
|
|
|
xucd.entry_size = archive_entry_size(entry);
|
|
|
|
xucd.entry_is_conf = false;
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2011-01-20 07:25:40 +05:30
|
|
|
if (strcmp("./INSTALL", entry_pname) == 0) {
|
|
|
|
/*
|
2011-01-21 21:46:58 +05:30
|
|
|
* Extract the INSTALL script first to execute
|
|
|
|
* the pre install target.
|
2011-01-20 07:25:40 +05:30
|
|
|
*/
|
2011-12-15 15:49:20 +05:30
|
|
|
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
|
2009-08-17 22:37:20 +05:30
|
|
|
XBPS_META_PATH, pkgname);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = extract_metafile(xhp, ar, entry,
|
|
|
|
"INSTALL", pkgver, true, flags);
|
2011-12-24 16:37:30 +05:30
|
|
|
if (rv != 0)
|
2011-01-21 21:46:58 +05:30
|
|
|
goto out;
|
2011-12-24 16:37:30 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = xbps_file_exec(xhp, buf, "pre",
|
2011-12-15 16:54:59 +05:30
|
|
|
pkgname, version, update ? "yes" : "no",
|
|
|
|
xhp->conffile, NULL);
|
2011-01-20 07:25:40 +05:30
|
|
|
free(buf);
|
2011-12-24 16:37:30 +05:30
|
|
|
buf = NULL;
|
2010-05-18 17:10:51 +05:30
|
|
|
if (rv != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
|
|
|
XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [unpack] INSTALL script failed "
|
|
|
|
"to execute pre ACTION: %s",
|
|
|
|
pkgver, strerror(rv));
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
continue;
|
2011-01-21 21:46:58 +05:30
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
} else if (strcmp("./REMOVE", entry_pname) == 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = extract_metafile(xhp, ar, entry,
|
|
|
|
"REMOVE", pkgver, true, flags);
|
2011-01-21 21:46:58 +05:30
|
|
|
if (rv != 0)
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2011-01-21 21:46:58 +05:30
|
|
|
|
2010-01-23 04:26:39 +05:30
|
|
|
continue;
|
2009-12-11 15:28:46 +05:30
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
} else if (strcmp("./files.plist", entry_pname) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2011-01-21 21:46:58 +05:30
|
|
|
* Internalize this entry into a prop_dictionary
|
|
|
|
* to check for obsolete files if updating a package.
|
|
|
|
* It will be extracted to disk at the end.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2011-06-02 13:24:59 +05:30
|
|
|
filesd = xbps_dictionary_from_archive_entry(ar, entry);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (filesd == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
} else if (strcmp("./props.plist", entry_pname) == 0) {
|
2012-09-30 00:19:51 +05:30
|
|
|
propsd = xbps_dictionary_from_archive_entry(ar, entry);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (propsd == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
continue;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
/*
|
|
|
|
* If XBPS_PKGFILES or XBPS_PKGPROPS weren't found
|
|
|
|
* in the archive at this phase, skip all data.
|
|
|
|
*/
|
2011-01-20 07:25:40 +05:30
|
|
|
if (propsd == NULL || filesd == NULL) {
|
2010-01-23 04:26:39 +05:30
|
|
|
archive_read_data_skip(ar);
|
|
|
|
/*
|
|
|
|
* If we have processed 4 entries and the two
|
|
|
|
* required metadata files weren't found, bail out.
|
|
|
|
* This is not an XBPS binary package.
|
|
|
|
*/
|
2011-01-21 21:46:58 +05:30
|
|
|
if (entry_idx >= 3) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
|
|
|
XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
ENODEV, pkgname, version,
|
|
|
|
"%s: [unpack] invalid binary package `%s'.",
|
|
|
|
pkgver, fname);
|
|
|
|
rv = ENODEV;
|
|
|
|
goto out;
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
|
|
|
|
entry_idx++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
/*
|
|
|
|
* Compute total entries in progress data, if set.
|
2012-05-06 20:18:47 +05:30
|
|
|
* total_entries = files + conf_files + links.
|
2011-01-21 21:46:58 +05:30
|
|
|
*/
|
2012-08-31 13:44:33 +05:30
|
|
|
if (xhp->unpack_cb != NULL) {
|
|
|
|
xucd.entry_total_count = 0;
|
2011-11-24 15:53:08 +05:30
|
|
|
array = prop_dictionary_get(filesd, "files");
|
2012-08-31 13:44:33 +05:30
|
|
|
xucd.entry_total_count +=
|
2011-11-24 15:53:08 +05:30
|
|
|
(ssize_t)prop_array_count(array);
|
|
|
|
array = prop_dictionary_get(filesd, "conf_files");
|
2012-08-31 13:44:33 +05:30
|
|
|
xucd.entry_total_count +=
|
2011-11-24 15:53:08 +05:30
|
|
|
(ssize_t)prop_array_count(array);
|
|
|
|
array = prop_dictionary_get(filesd, "links");
|
2012-08-31 13:44:33 +05:30
|
|
|
xucd.entry_total_count +=
|
2011-11-24 15:53:08 +05:30
|
|
|
(ssize_t)prop_array_count(array);
|
|
|
|
}
|
2011-12-19 15:50:27 +05:30
|
|
|
/*
|
|
|
|
* Always check that extracted file exists and hash
|
|
|
|
* doesn't match, in that case overwrite the file.
|
|
|
|
* Otherwise skip extracting it.
|
|
|
|
*/
|
2012-09-30 00:19:51 +05:30
|
|
|
conf_file = file_exists = false;
|
2012-10-26 13:57:24 +05:30
|
|
|
rv_stat = stat(entry_pname, &st);
|
|
|
|
|
2011-12-19 15:50:27 +05:30
|
|
|
if (S_ISREG(entry_statp->st_mode)) {
|
2012-09-30 20:37:51 +05:30
|
|
|
buf = strchr(entry_pname, '.') + 1;
|
|
|
|
assert(buf != NULL);
|
2012-10-26 13:57:24 +05:30
|
|
|
if (rv_stat == 0) {
|
2011-12-19 15:50:27 +05:30
|
|
|
file_exists = true;
|
2012-10-26 13:57:24 +05:30
|
|
|
/*
|
|
|
|
* Handle configuration files. Check if current
|
|
|
|
* entry is a configuration file and take action
|
|
|
|
* if required. Skip packages that don't have
|
|
|
|
* "conf_files" array on its XBPS_PKGPROPS
|
|
|
|
* dictionary.
|
|
|
|
*/
|
|
|
|
if (xbps_entry_is_a_conf_file(propsd, buf)) {
|
|
|
|
conf_file = true;
|
|
|
|
if (xhp->unpack_cb != NULL)
|
|
|
|
xucd.entry_is_conf = true;
|
|
|
|
|
|
|
|
rv = xbps_entry_install_conf_file(xhp,
|
|
|
|
filesd, entry, entry_pname,
|
|
|
|
pkgname, version);
|
|
|
|
if (rv == -1) {
|
|
|
|
/* error */
|
|
|
|
goto out;
|
|
|
|
} else if (rv == 0) {
|
|
|
|
/*
|
|
|
|
* Keep curfile as is.
|
|
|
|
*/
|
|
|
|
skip_extract = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = xbps_file_hash_check_dictionary(
|
|
|
|
xhp, filesd, "files", buf);
|
|
|
|
if (rv == -1) {
|
|
|
|
/* error */
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp,
|
2012-10-26 13:57:24 +05:30
|
|
|
"%s-%s: failed to check"
|
|
|
|
" hash for `%s': %s\n",
|
2012-03-07 16:30:08 +05:30
|
|
|
pkgname, version,
|
|
|
|
entry_pname,
|
|
|
|
strerror(errno));
|
|
|
|
goto out;
|
2012-10-26 13:57:24 +05:30
|
|
|
} else if (rv == 0) {
|
|
|
|
/*
|
|
|
|
* hash match, skip extraction.
|
|
|
|
*/
|
|
|
|
xbps_dbg_printf(xhp,
|
|
|
|
"%s-%s: file %s "
|
|
|
|
"matches existing SHA256, "
|
|
|
|
"skipping...\n", pkgname,
|
|
|
|
version, entry_pname);
|
|
|
|
skip_extract = true;
|
2012-03-07 16:30:08 +05:30
|
|
|
}
|
2011-08-01 16:05:47 +05:30
|
|
|
}
|
2011-12-19 15:50:27 +05:30
|
|
|
}
|
2012-10-26 13:57:24 +05:30
|
|
|
} else if (S_ISLNK(entry_statp->st_mode)) {
|
|
|
|
/*
|
|
|
|
* Check if current link from binpkg hasn't been
|
|
|
|
* modified, otherwise extract new link.
|
|
|
|
*/
|
|
|
|
if (stat(entry_pname, &st) == 0) {
|
|
|
|
buf = realpath(entry_pname, NULL);
|
|
|
|
assert(buf);
|
|
|
|
p = strlen(xhp->rootdir) + buf;
|
|
|
|
assert(p);
|
|
|
|
tgtlnk = find_pkg_symlink_target(filesd,
|
|
|
|
entry_pname);
|
|
|
|
assert(tgtlnk);
|
|
|
|
p2 = xbps_xasprintf(".%s", tgtlnk);
|
|
|
|
assert(p2);
|
|
|
|
buf2 = realpath(p2, NULL);
|
|
|
|
assert(buf2);
|
|
|
|
free(p2);
|
|
|
|
p2 = strlen(xhp->rootdir) + buf2;
|
|
|
|
if (strcmp(p, p2) == 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s-%s: symlink "
|
|
|
|
"%s matched, skipping...\n",
|
|
|
|
pkgname, version, entry_pname);
|
|
|
|
skip_extract = true;
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
free(buf2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if current file mode differs from file mode
|
|
|
|
* in binpkg and apply perms if true.
|
|
|
|
*/
|
|
|
|
if (file_exists && (entry_statp->st_mode != st.st_mode)) {
|
|
|
|
if (chmod(entry_pname,
|
|
|
|
entry_statp->st_mode) != 0) {
|
|
|
|
xbps_dbg_printf(xhp,
|
|
|
|
"%s-%s: failed "
|
|
|
|
"to set perms %s to %s: %s\n",
|
|
|
|
pkgname, version,
|
|
|
|
archive_entry_strmode(entry),
|
|
|
|
entry_pname,
|
|
|
|
strerror(errno));
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
xbps_dbg_printf(xhp, "%s-%s: entry %s perms "
|
|
|
|
"to %s.\n", pkgname, version, entry_pname,
|
|
|
|
archive_entry_strmode(entry));
|
|
|
|
skip_extract = true;
|
2011-12-19 15:50:27 +05:30
|
|
|
}
|
2012-10-26 13:57:24 +05:30
|
|
|
|
|
|
|
if (!update && conf_file && file_exists && !skip_extract) {
|
2011-12-19 15:50:27 +05:30
|
|
|
/*
|
|
|
|
* If installing new package preserve old configuration
|
|
|
|
* file but renaming it to <file>.old.
|
|
|
|
*/
|
|
|
|
buf = xbps_xasprintf("%s.old", entry_pname);
|
2012-09-30 00:19:51 +05:30
|
|
|
assert(buf);
|
2011-12-19 15:50:27 +05:30
|
|
|
(void)rename(entry_pname, buf);
|
|
|
|
free(buf);
|
2011-12-24 16:37:30 +05:30
|
|
|
buf = NULL;
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
|
|
|
XBPS_STATE_CONFIG_FILE, 0,
|
2011-12-19 15:50:27 +05:30
|
|
|
pkgname, version,
|
|
|
|
"Renamed old configuration file "
|
|
|
|
"`%s' to `%s.old'.", entry_pname, entry_pname);
|
2012-10-26 13:57:24 +05:30
|
|
|
}
|
2011-12-19 15:50:27 +05:30
|
|
|
|
2012-10-26 13:57:24 +05:30
|
|
|
if (skip_extract) {
|
|
|
|
archive_read_data_skip(ar);
|
|
|
|
continue;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2012-10-01 20:11:50 +05:30
|
|
|
/*
|
|
|
|
* Reset entry_pname again because if entry's pathname
|
|
|
|
* has been changed it will become a dangling pointer.
|
|
|
|
*/
|
|
|
|
entry_pname = archive_entry_pathname(entry);
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Extract entry from archive.
|
|
|
|
*/
|
2011-01-21 21:46:58 +05:30
|
|
|
if (archive_read_extract(ar, entry, flags) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = archive_errno(ar);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [unpack] failed to extract file `%s': %s",
|
|
|
|
pkgver, entry_pname, strerror(rv));
|
2012-10-26 13:57:24 +05:30
|
|
|
} else {
|
|
|
|
if (xhp->unpack_cb != NULL) {
|
|
|
|
xucd.entry_extract_count++;
|
|
|
|
(*xhp->unpack_cb)(xhp, &xucd, xhp->unpack_cb_data);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
2011-11-10 01:31:25 +05:30
|
|
|
/*
|
|
|
|
* If there was any error extracting files from archive, error out.
|
|
|
|
*/
|
|
|
|
if ((rv = archive_errno(ar)) != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
2012-06-05 20:16:50 +05:30
|
|
|
"%s: [unpack] failed to extract files: %s",
|
|
|
|
pkgver, fname, archive_error_string(ar));
|
2011-11-10 01:31:25 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
2012-02-21 00:53:33 +05:30
|
|
|
* Skip checking for obsolete files on:
|
2012-05-26 02:14:58 +05:30
|
|
|
* - New package installation without "softreplace" keyword.
|
|
|
|
* - Package with "preserve" keyword.
|
|
|
|
* - Package with "skip-obsoletes" keyword.
|
2011-11-10 01:31:25 +05:30
|
|
|
*/
|
2011-12-15 15:49:20 +05:30
|
|
|
pkgfilesd = xbps_xasprintf("%s/metadata/%s/%s",
|
2011-11-10 01:31:25 +05:30
|
|
|
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
|
|
|
if (pkgfilesd == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-26 02:14:58 +05:30
|
|
|
if (skip_obsoletes || preserve || (!softreplace && !update))
|
2011-11-10 01:31:25 +05:30
|
|
|
goto out1;
|
|
|
|
/*
|
2012-10-24 11:15:00 +05:30
|
|
|
* Check and remove obsolete files on:
|
2012-05-26 02:14:58 +05:30
|
|
|
* - Package upgrade.
|
|
|
|
* - Package with "softreplace" keyword.
|
2011-11-10 01:31:25 +05:30
|
|
|
*/
|
|
|
|
old_filesd = prop_dictionary_internalize_from_zfile(pkgfilesd);
|
|
|
|
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) {
|
2012-10-24 11:15:00 +05:30
|
|
|
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
|
|
|
|
for (i = 0; i < prop_array_count(obsoletes); i++) {
|
|
|
|
obj = prop_array_get(obsoletes, i);
|
|
|
|
file = prop_string_cstring_nocopy(obj);
|
|
|
|
if (remove(file) == -1) {
|
|
|
|
xbps_set_cb_state(xhp,
|
|
|
|
XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
|
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: failed to remove obsolete entry `%s': %s",
|
|
|
|
pkgver, file, strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
xbps_set_cb_state(xhp,
|
|
|
|
XBPS_STATE_REMOVE_FILE_OBSOLETE,
|
|
|
|
0, pkgname, version,
|
|
|
|
"%s: removed obsolete entry: %s", pkgver, file);
|
|
|
|
prop_object_release(obj);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-10-24 11:15:00 +05:30
|
|
|
prop_object_release(old_filesd);
|
2011-11-10 01:31:25 +05:30
|
|
|
}
|
|
|
|
out1:
|
|
|
|
/*
|
2012-10-26 13:57:24 +05:30
|
|
|
* Create pkg metadata directory if doesn't exist.
|
2011-11-10 01:31:25 +05:30
|
|
|
*/
|
2011-12-15 15:49:20 +05:30
|
|
|
buf = xbps_xasprintf("%s/metadata/%s", XBPS_META_PATH, pkgname);
|
2011-11-10 01:31:25 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-10-26 13:57:24 +05:30
|
|
|
if (access(buf, R_OK|X_OK) == -1) {
|
|
|
|
if (xbps_mkpath(buf, 0755) == -1) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] failed to create pkg metadir "
|
|
|
|
"`%s': %s", buf, pkgver, strerror(errno));
|
|
|
|
free(buf);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-11-10 01:31:25 +05:30
|
|
|
}
|
2012-09-30 00:19:51 +05:30
|
|
|
free(buf);
|
2011-11-10 01:31:25 +05:30
|
|
|
/*
|
2012-09-30 00:19:51 +05:30
|
|
|
* Externalize XBPS_PKGFILES and XBPS_PKGPROPS into pkg's
|
|
|
|
* metadata directory.
|
2011-11-10 01:31:25 +05:30
|
|
|
*/
|
2012-09-30 00:19:51 +05:30
|
|
|
if (!prop_dictionary_externalize_to_file(filesd, pkgfilesd)) {
|
2011-11-10 01:31:25 +05:30
|
|
|
rv = errno;
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] failed to extract metadata file `%s': %s",
|
|
|
|
pkgver, XBPS_PKGFILES, strerror(errno));
|
2011-11-10 01:31:25 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-09-30 00:19:51 +05:30
|
|
|
pkgpropsd = xbps_xasprintf("%s/metadata/%s/%s",
|
|
|
|
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
|
|
|
if (pkgpropsd == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!prop_dictionary_externalize_to_file(propsd, pkgpropsd)) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] failed to extract metadata file `%s': %s",
|
|
|
|
pkgver, XBPS_PKGPROPS, strerror(errno));
|
|
|
|
goto out;
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
out:
|
2011-11-10 01:31:25 +05:30
|
|
|
if (pkgfilesd != NULL)
|
|
|
|
free(pkgfilesd);
|
2012-09-30 00:19:51 +05:30
|
|
|
if (pkgpropsd != NULL)
|
|
|
|
free(pkgpropsd);
|
2011-11-10 01:31:25 +05:30
|
|
|
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
|
2010-01-19 00:19:32 +05:30
|
|
|
prop_object_release(filesd);
|
2011-11-10 01:31:25 +05:30
|
|
|
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
|
2010-11-19 18:10:13 +05:30
|
|
|
prop_object_release(propsd);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
|
2012-01-17 20:47:03 +05:30
|
|
|
int HIDDEN
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
2011-12-22 12:53:11 +05:30
|
|
|
struct archive *ar = NULL;
|
2011-07-30 02:58:36 +05:30
|
|
|
const char *pkgname, *version, *repoloc, *pkgver, *fname;
|
2011-12-22 12:53:11 +05:30
|
|
|
char *bpkg = NULL;
|
2011-01-21 21:46:58 +05:30
|
|
|
int rv = 0;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);
|
2011-02-22 15:39:39 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
2011-01-20 21:11:49 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
|
2011-07-30 02:58:36 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname);
|
2010-11-06 11:14:00 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK, 0, pkgname, version, NULL);
|
2011-11-24 15:53:08 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
bpkg = xbps_path_from_repository_uri(xhp, pkg_repod, repoloc);
|
2011-01-21 21:46:58 +05:30
|
|
|
if (bpkg == NULL) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [unpack] cannot determine binary package "
|
|
|
|
"file for `%s': %s", pkgver, fname, strerror(errno));
|
2011-01-21 21:46:58 +05:30
|
|
|
return errno;
|
2010-01-21 07:40:19 +05:30
|
|
|
}
|
|
|
|
|
2011-07-28 19:55:01 +05:30
|
|
|
if ((ar = archive_read_new()) == NULL) {
|
2011-12-22 12:53:11 +05:30
|
|
|
free(bpkg);
|
|
|
|
return ENOMEM;
|
2010-01-21 07:40:19 +05:30
|
|
|
}
|
|
|
|
/*
|
2012-02-22 08:46:36 +05:30
|
|
|
* Enable support for tar format and gzip/bzip2/lzma compression methods.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
2012-02-22 08:46:36 +05:30
|
|
|
archive_read_support_compression_gzip(ar);
|
|
|
|
archive_read_support_compression_bzip2(ar);
|
|
|
|
archive_read_support_compression_xz(ar);
|
2010-01-21 07:40:19 +05:30
|
|
|
archive_read_support_format_tar(ar);
|
|
|
|
|
2011-01-21 21:46:58 +05:30
|
|
|
if (archive_read_open_filename(ar, bpkg, ARCHIVE_READ_BLOCKSIZE) != 0) {
|
|
|
|
rv = archive_errno(ar);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [unpack] failed to open binary package `%s': %s",
|
|
|
|
pkgver, fname, strerror(rv));
|
2011-12-22 12:53:11 +05:30
|
|
|
free(bpkg);
|
2012-06-13 01:52:46 +05:30
|
|
|
archive_read_free(ar);
|
2011-12-22 12:53:11 +05:30
|
|
|
return rv;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2011-12-22 12:53:11 +05:30
|
|
|
free(bpkg);
|
|
|
|
|
2011-07-28 19:55:01 +05:30
|
|
|
/*
|
|
|
|
* Set package state to half-unpacked.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
|
2011-07-28 19:55:01 +05:30
|
|
|
XBPS_PKG_STATE_HALF_UNPACKED)) != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [unpack] failed to set state to half-unpacked: %s",
|
|
|
|
pkgver, strerror(rv));
|
2011-07-28 19:55:01 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
/*
|
|
|
|
* Extract archive files.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = unpack_archive(xhp, pkg_repod, ar)) != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
2011-12-24 16:37:30 +05:30
|
|
|
"%s: [unpack] failed to unpack files from archive: %s",
|
2011-11-24 15:53:08 +05:30
|
|
|
pkgver, strerror(rv));
|
2010-01-23 04:26:39 +05:30
|
|
|
goto out;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
/*
|
|
|
|
* Set package state to unpacked.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
|
2011-07-28 19:55:01 +05:30
|
|
|
XBPS_PKG_STATE_UNPACKED)) != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [unpack] failed to set state to unpacked: %s",
|
|
|
|
pkgver, strerror(rv));
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
out:
|
2012-06-05 20:16:50 +05:30
|
|
|
if (ar) {
|
|
|
|
archive_read_close(ar);
|
|
|
|
archive_read_free(ar);
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
return rv;
|
|
|
|
}
|