2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2013-02-05 16:40:24 +05:30
|
|
|
* Copyright (c) 2008-2013 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.
|
|
|
|
*/
|
|
|
|
|
2012-12-15 15:17:30 +05:30
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
2012-10-26 14:55:17 +05:30
|
|
|
set_extract_flags(uid_t euid)
|
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
|
|
|
|
2012-10-26 14:55:17 +05:30
|
|
|
if (euid == 0)
|
2011-07-28 19:55:01 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-10-26 13:57:24 +05:30
|
|
|
static const char *
|
2013-06-20 13:56:12 +05:30
|
|
|
find_pkg_symlink_target(xbps_dictionary_t d, const char *file)
|
2012-10-26 13:57:24 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t links;
|
|
|
|
xbps_object_t obj;
|
2012-10-26 13:57:24 +05:30
|
|
|
const char *pkgfile, *tgt = NULL;
|
|
|
|
char *rfile;
|
|
|
|
|
|
|
|
assert(d);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
links = xbps_dictionary_get(d, "links");
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(links); i++) {
|
2012-10-26 13:57:24 +05:30
|
|
|
rfile = strchr(file, '.') + 1;
|
2013-06-20 13:56:12 +05:30
|
|
|
obj = xbps_array_get(links, i);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "file", &pkgfile);
|
2012-10-26 13:57:24 +05:30
|
|
|
if (strcmp(rfile, pkgfile) == 0) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "target", &tgt);
|
2012-10-26 13:57:24 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tgt;
|
|
|
|
}
|
|
|
|
|
2013-05-17 11:54:47 +05:30
|
|
|
static int
|
|
|
|
create_pkg_metaplist(struct xbps_handle *xhp, const char *pkgname, const char *pkgver,
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t propsd, xbps_dictionary_t filesd,
|
2013-05-17 11:54:47 +05:30
|
|
|
const void *instbuf, const size_t instbufsiz,
|
|
|
|
const void *rembuf, const size_t rembufsiz)
|
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t array;
|
|
|
|
xbps_dictionary_t pkg_metad;
|
|
|
|
xbps_data_t data;
|
2013-05-17 11:54:47 +05:30
|
|
|
char *buf;
|
|
|
|
int rv = 0;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_make_immutable(propsd);
|
|
|
|
pkg_metad = xbps_dictionary_copy_mutable(propsd);
|
2013-05-17 11:54:47 +05:30
|
|
|
|
|
|
|
/* Add objects from XBPS_PKGFILES */
|
2013-06-20 13:56:12 +05:30
|
|
|
array = xbps_dictionary_get(filesd, "files");
|
|
|
|
if (xbps_array_count(array))
|
|
|
|
xbps_dictionary_set(pkg_metad, "files", array);
|
|
|
|
array = xbps_dictionary_get(filesd, "conf_files");
|
|
|
|
if (xbps_array_count(array))
|
|
|
|
xbps_dictionary_set(pkg_metad, "conf_files", array);
|
|
|
|
array = xbps_dictionary_get(filesd, "links");
|
|
|
|
if (xbps_array_count(array))
|
|
|
|
xbps_dictionary_set(pkg_metad, "links", array);
|
|
|
|
array = xbps_dictionary_get(filesd, "dirs");
|
|
|
|
if (xbps_array_count(array))
|
|
|
|
xbps_dictionary_set(pkg_metad, "dirs", array);
|
2013-05-17 11:54:47 +05:30
|
|
|
|
|
|
|
/* Add install/remove scripts data objects */
|
|
|
|
if (instbuf != NULL) {
|
2013-06-20 13:56:12 +05:30
|
|
|
data = xbps_data_create_data(instbuf, instbufsiz);
|
2013-05-17 11:54:47 +05:30
|
|
|
assert(data);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set(pkg_metad, "install-script", data);
|
|
|
|
xbps_object_release(data);
|
2013-05-17 11:54:47 +05:30
|
|
|
}
|
|
|
|
if (rembuf != NULL) {
|
2013-06-20 13:56:12 +05:30
|
|
|
data = xbps_data_create_data(rembuf, rembufsiz);
|
2013-05-17 11:54:47 +05:30
|
|
|
assert(data);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set(pkg_metad, "remove-script", data);
|
|
|
|
xbps_object_release(data);
|
2013-05-17 11:54:47 +05:30
|
|
|
}
|
|
|
|
/* Remove unneeded objs from transaction */
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_remove(pkg_metad, "remove-and-update");
|
|
|
|
xbps_dictionary_remove(pkg_metad, "transaction");
|
|
|
|
xbps_dictionary_remove(pkg_metad, "state");
|
|
|
|
xbps_dictionary_remove(pkg_metad, "pkgname");
|
|
|
|
xbps_dictionary_remove(pkg_metad, "version");
|
2013-05-17 11:54:47 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Externalize pkg dictionary to metadir.
|
|
|
|
*/
|
|
|
|
if (access(xhp->metadir, R_OK|X_OK) == -1) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
xbps_mkpath(xhp->metadir, 0755);
|
|
|
|
} else {
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf = xbps_xasprintf("%s/.%s.plist", XBPS_META_PATH, pkgname);
|
2013-06-20 13:56:12 +05:30
|
|
|
if (!xbps_dictionary_externalize_to_file(pkg_metad, buf)) {
|
2013-05-17 11:54:47 +05:30
|
|
|
rv = errno;
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
errno, pkgver,
|
|
|
|
"%s: [unpack] failed to write metadata file `%s': %s",
|
|
|
|
pkgver, buf, strerror(errno));
|
|
|
|
}
|
|
|
|
free(buf);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(pkg_metad);
|
2013-05-17 11:54:47 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
unpack_archive(struct xbps_handle *xhp,
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkg_repod,
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *pkgver,
|
|
|
|
const char *fname,
|
2012-06-14 11:52:11 +05:30
|
|
|
struct archive *ar)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t propsd, filesd, old_filesd;
|
|
|
|
xbps_array_t array, obsoletes;
|
|
|
|
xbps_object_t obj;
|
2012-11-18 16:37:43 +05:30
|
|
|
void *instbuf = NULL, *rembuf = NULL;
|
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;
|
2013-09-15 13:36:49 +05:30
|
|
|
size_t instbufsiz = 0, rembufsiz = 0;
|
2012-11-16 21:25:35 +05:30
|
|
|
ssize_t entry_size;
|
2013-09-15 13:36:49 +05:30
|
|
|
unsigned int entry_idx = 0;
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *file, *entry_pname, *transact, *tgtlnk;
|
|
|
|
char *pkgname, *dname, *buf, *buf2, *p, *p2;
|
2013-03-15 17:48:30 +05:30
|
|
|
int ar_rv, rv, entry_type, flags;
|
2012-02-21 00:53:33 +05:30
|
|
|
bool preserve, update, conf_file, file_exists, skip_obsoletes;
|
2013-05-17 12:47:32 +05:30
|
|
|
bool softreplace, skip_extract, force, metafile;
|
2012-10-26 14:55:17 +05:30
|
|
|
uid_t euid;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
|
2009-08-17 22:37:20 +05:30
|
|
|
assert(ar != NULL);
|
2009-12-02 11:01:03 +05:30
|
|
|
|
2013-05-17 11:54:47 +05:30
|
|
|
propsd = filesd = old_filesd = NULL;
|
2012-11-20 01:20:58 +05:30
|
|
|
force = preserve = update = conf_file = file_exists = false;
|
2013-05-17 12:47:32 +05:30
|
|
|
skip_obsoletes = softreplace = metafile = false;
|
2012-05-26 02:14:58 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_bool(pkg_repod, "preserve", &preserve);
|
|
|
|
xbps_dictionary_get_bool(pkg_repod, "skip-obsoletes", &skip_obsoletes);
|
|
|
|
xbps_dictionary_get_bool(pkg_repod, "softreplace", &softreplace);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_repod,
|
2011-02-05 16:51:04 +05:30
|
|
|
"transaction", &transact);
|
2011-11-24 15:53:08 +05:30
|
|
|
|
2012-10-26 14:55:17 +05:30
|
|
|
euid = geteuid();
|
|
|
|
|
2013-03-05 11:12:25 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
|
|
|
|
2013-02-02 16:00:42 +05:30
|
|
|
if (xhp->flags & XBPS_FLAG_FORCE_UNPACK)
|
2012-11-20 01:20:58 +05:30
|
|
|
force = true;
|
|
|
|
|
2011-11-24 15:53:08 +05:30
|
|
|
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,
|
2013-03-05 08:38:42 +05:30
|
|
|
errno, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%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-23 04:26:39 +05:30
|
|
|
/*
|
|
|
|
* Process the archive files.
|
|
|
|
*/
|
2013-03-15 17:48:30 +05:30
|
|
|
flags = set_extract_flags(euid);
|
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;
|
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
entry_pname = archive_entry_pathname(entry);
|
2012-11-16 21:25:35 +05:30
|
|
|
entry_size = archive_entry_size(entry);
|
2013-03-15 17:48:30 +05:30
|
|
|
entry_type = archive_entry_filetype(entry);
|
2011-11-10 01:31:25 +05:30
|
|
|
/*
|
|
|
|
* Ignore directories from archive.
|
|
|
|
*/
|
2013-03-15 17:48:30 +05:30
|
|
|
if (entry_type == AE_IFDIR) {
|
2011-11-10 01:31:25 +05:30
|
|
|
archive_read_data_skip(ar);
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-20 07:25:40 +05:30
|
|
|
if (strcmp("./INSTALL", entry_pname) == 0) {
|
|
|
|
/*
|
2012-11-16 21:25:35 +05:30
|
|
|
* Store file in a buffer and execute
|
|
|
|
* the "pre" action from it.
|
2011-01-20 07:25:40 +05:30
|
|
|
*/
|
2012-11-16 21:25:35 +05:30
|
|
|
instbufsiz = entry_size;
|
|
|
|
instbuf = malloc(entry_size);
|
|
|
|
assert(instbuf);
|
|
|
|
|
|
|
|
if (archive_read_data(ar, instbuf, entry_size) !=
|
|
|
|
entry_size) {
|
|
|
|
rv = EINVAL;
|
2011-01-21 21:46:58 +05:30
|
|
|
goto out;
|
2012-11-16 21:25:35 +05:30
|
|
|
}
|
2011-12-24 16:37:30 +05:30
|
|
|
|
2012-11-16 21:25:35 +05:30
|
|
|
rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz,
|
2013-03-07 16:31:07 +05:30
|
|
|
pkgver, "pre", update);
|
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,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%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-11-16 21:25:35 +05:30
|
|
|
/* store file in a buffer */
|
|
|
|
rembufsiz = entry_size;
|
|
|
|
rembuf = malloc(entry_size);
|
|
|
|
assert(rembuf);
|
|
|
|
if (archive_read_data(ar, rembuf, entry_size) !=
|
|
|
|
entry_size) {
|
|
|
|
rv = EINVAL;
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2012-11-16 21:25:35 +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) {
|
2013-06-10 13:58:39 +05:30
|
|
|
filesd = xbps_archive_get_dictionary(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;
|
2012-11-15 13:57:41 +05:30
|
|
|
} else if (strcmp("./props.plist", entry_pname) == 0) {
|
2013-06-10 13:58:39 +05:30
|
|
|
propsd = xbps_archive_get_dictionary(ar, entry);
|
2013-03-05 08:38:42 +05:30
|
|
|
if (propsd == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-05-17 12:47:32 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX: duplicate code.
|
|
|
|
* Create the metaplist file before unpacking any real file.
|
|
|
|
*/
|
|
|
|
if (propsd && filesd && !metafile) {
|
2013-05-17 11:54:47 +05:30
|
|
|
rv = create_pkg_metaplist(xhp, pkgname, pkgver,
|
|
|
|
propsd, filesd, instbuf, instbufsiz,
|
|
|
|
rembuf, rembufsiz);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
rv, pkgver,
|
|
|
|
"%s: [unpack] failed to create metaplist file: %s",
|
|
|
|
pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
2013-05-17 12:47:32 +05:30
|
|
|
metafile = true;
|
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.
|
|
|
|
*/
|
2013-03-05 08:38:42 +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,
|
2013-03-09 15:37:14 +05:30
|
|
|
XBPS_STATE_UNPACK_FAIL, ENODEV, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%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;
|
|
|
|
}
|
2013-05-17 11:54:47 +05:30
|
|
|
/*
|
|
|
|
* Prepare unpack callback ops.
|
|
|
|
*/
|
|
|
|
if (xhp->unpack_cb != NULL) {
|
|
|
|
xucd.xhp = xhp;
|
|
|
|
xucd.pkgver = pkgver;
|
|
|
|
xucd.entry = entry_pname;
|
|
|
|
xucd.entry_size = entry_size;
|
|
|
|
xucd.entry_is_conf = false;
|
|
|
|
}
|
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;
|
2013-06-20 13:56:12 +05:30
|
|
|
array = xbps_dictionary_get(filesd, "files");
|
2012-08-31 13:44:33 +05:30
|
|
|
xucd.entry_total_count +=
|
2013-06-20 13:56:12 +05:30
|
|
|
(ssize_t)xbps_array_count(array);
|
|
|
|
array = xbps_dictionary_get(filesd, "conf_files");
|
2012-08-31 13:44:33 +05:30
|
|
|
xucd.entry_total_count +=
|
2013-06-20 13:56:12 +05:30
|
|
|
(ssize_t)xbps_array_count(array);
|
|
|
|
array = xbps_dictionary_get(filesd, "links");
|
2012-08-31 13:44:33 +05:30
|
|
|
xucd.entry_total_count +=
|
2013-06-20 13:56:12 +05:30
|
|
|
(ssize_t)xbps_array_count(array);
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
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-10-26 14:55:17 +05:30
|
|
|
conf_file = skip_extract = file_exists = false;
|
2013-03-11 18:36:47 +05:30
|
|
|
if (lstat(entry_pname, &st) == 0)
|
2012-10-26 14:55:17 +05:30
|
|
|
file_exists = true;
|
2012-10-26 13:57:24 +05:30
|
|
|
|
2013-03-15 17:48:30 +05:30
|
|
|
if (!force && (entry_type == AE_IFREG)) {
|
2012-09-30 20:37:51 +05:30
|
|
|
buf = strchr(entry_pname, '.') + 1;
|
|
|
|
assert(buf != NULL);
|
2012-10-26 14:55:17 +05:30
|
|
|
if (file_exists) {
|
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.
|
|
|
|
*/
|
2013-03-05 08:38:42 +05:30
|
|
|
if (xbps_entry_is_a_conf_file(propsd, buf)) {
|
2012-10-26 13:57:24 +05:30
|
|
|
conf_file = true;
|
|
|
|
if (xhp->unpack_cb != NULL)
|
|
|
|
xucd.entry_is_conf = true;
|
|
|
|
|
|
|
|
rv = xbps_entry_install_conf_file(xhp,
|
2013-03-08 14:41:16 +05:30
|
|
|
filesd, entry, entry_pname, pkgver,
|
|
|
|
pkgname);
|
2012-10-26 13:57:24 +05:30
|
|
|
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,
|
2013-03-05 08:38:42 +05:30
|
|
|
"%s: failed to check"
|
2012-10-26 13:57:24 +05:30
|
|
|
" hash for `%s': %s\n",
|
2013-03-05 08:38:42 +05:30
|
|
|
pkgver, entry_pname,
|
2012-03-07 16:30:08 +05:30
|
|
|
strerror(errno));
|
|
|
|
goto out;
|
2012-10-26 13:57:24 +05:30
|
|
|
} else if (rv == 0) {
|
|
|
|
/*
|
|
|
|
* hash match, skip extraction.
|
|
|
|
*/
|
|
|
|
xbps_dbg_printf(xhp,
|
2013-03-05 08:38:42 +05:30
|
|
|
"%s: file %s "
|
2012-10-26 13:57:24 +05:30
|
|
|
"matches existing SHA256, "
|
2013-03-05 08:38:42 +05:30
|
|
|
"skipping...\n",
|
|
|
|
pkgver, entry_pname);
|
2012-10-26 13:57:24 +05:30
|
|
|
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
|
|
|
}
|
2013-03-15 17:48:30 +05:30
|
|
|
} else if (!force && (entry_type == AE_IFLNK)) {
|
2012-10-26 13:57:24 +05:30
|
|
|
/*
|
|
|
|
* Check if current link from binpkg hasn't been
|
|
|
|
* modified, otherwise extract new link.
|
|
|
|
*/
|
2012-11-12 21:40:02 +05:30
|
|
|
buf = realpath(entry_pname, NULL);
|
|
|
|
if (buf) {
|
2012-10-27 14:06:39 +05:30
|
|
|
if (strcmp(xhp->rootdir, "/")) {
|
|
|
|
p = buf;
|
|
|
|
p += strlen(xhp->rootdir);
|
|
|
|
} else
|
2012-10-26 17:47:31 +05:30
|
|
|
p = buf;
|
2012-10-26 13:57:24 +05:30
|
|
|
tgtlnk = find_pkg_symlink_target(filesd,
|
|
|
|
entry_pname);
|
|
|
|
assert(tgtlnk);
|
2012-10-26 17:47:31 +05:30
|
|
|
if (strncmp(tgtlnk, "./", 2) == 0) {
|
2012-10-27 14:06:39 +05:30
|
|
|
buf2 = strdup(entry_pname);
|
2012-10-27 13:06:28 +05:30
|
|
|
assert(buf2);
|
2012-10-27 14:06:39 +05:30
|
|
|
dname = dirname(buf2);
|
|
|
|
p2 = xbps_xasprintf("%s/%s", dname, tgtlnk);
|
|
|
|
free(buf2);
|
2012-10-26 17:47:31 +05:30
|
|
|
} else {
|
2012-10-27 14:06:39 +05:30
|
|
|
p2 = strdup(tgtlnk);
|
|
|
|
assert(p2);
|
2012-10-26 17:47:31 +05:30
|
|
|
}
|
2012-10-26 18:02:04 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: symlink %s cur: %s "
|
|
|
|
"new: %s\n", pkgver, entry_pname, p, p2);
|
2012-10-26 17:52:18 +05:30
|
|
|
|
2012-10-26 13:57:24 +05:30
|
|
|
if (strcmp(p, p2) == 0) {
|
2013-03-05 08:38:42 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: symlink "
|
2012-10-26 13:57:24 +05:30
|
|
|
"%s matched, skipping...\n",
|
2013-03-05 08:38:42 +05:30
|
|
|
pkgver, entry_pname);
|
2012-10-26 13:57:24 +05:30
|
|
|
skip_extract = true;
|
|
|
|
}
|
|
|
|
free(buf);
|
2013-03-09 15:37:14 +05:30
|
|
|
free(p2);
|
2012-10-26 13:57:24 +05:30
|
|
|
}
|
|
|
|
}
|
2012-10-26 14:55:17 +05:30
|
|
|
/*
|
|
|
|
* Check if current uid/gid differs from file in binpkg,
|
|
|
|
* and change permissions if true.
|
|
|
|
*/
|
2012-11-20 01:20:58 +05:30
|
|
|
if ((!force && file_exists && skip_extract && (euid == 0)) &&
|
2013-03-15 17:48:30 +05:30
|
|
|
(((archive_entry_uid(entry) != st.st_uid)) ||
|
|
|
|
((archive_entry_gid(entry) != st.st_gid)))) {
|
2013-03-17 21:43:07 +05:30
|
|
|
if (lchown(entry_pname,
|
2013-03-15 17:48:30 +05:30
|
|
|
archive_entry_uid(entry),
|
|
|
|
archive_entry_gid(entry)) != 0) {
|
2012-10-26 14:55:17 +05:30
|
|
|
xbps_dbg_printf(xhp,
|
2013-03-05 08:38:42 +05:30
|
|
|
"%s: failed "
|
2012-10-26 14:55:17 +05:30
|
|
|
"to set uid/gid to %u:%u (%s)\n",
|
2013-03-15 17:48:30 +05:30
|
|
|
pkgver, archive_entry_uid(entry),
|
|
|
|
archive_entry_gid(entry),
|
2012-10-26 14:55:17 +05:30
|
|
|
strerror(errno));
|
|
|
|
} else {
|
2013-03-05 08:38:42 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: entry %s changed "
|
|
|
|
"uid/gid to %u:%u.\n", pkgver, entry_pname,
|
2013-03-15 17:48:30 +05:30
|
|
|
archive_entry_uid(entry),
|
|
|
|
archive_entry_gid(entry));
|
2012-10-26 14:55:17 +05:30
|
|
|
}
|
2011-12-19 15:50:27 +05:30
|
|
|
}
|
2013-10-30 16:32:16 +05:30
|
|
|
/*
|
|
|
|
* Check if current file mode differs from file mode
|
|
|
|
* in binpkg and apply perms if true.
|
|
|
|
*/
|
|
|
|
if (!force && file_exists && skip_extract &&
|
|
|
|
(archive_entry_mode(entry) != st.st_mode)) {
|
|
|
|
if (chmod(entry_pname,
|
|
|
|
archive_entry_mode(entry)) != 0) {
|
|
|
|
xbps_dbg_printf(xhp,
|
|
|
|
"%s: failed "
|
|
|
|
"to set perms %s to %s: %s\n",
|
|
|
|
pkgver, archive_entry_strmode(entry),
|
|
|
|
entry_pname,
|
|
|
|
strerror(errno));
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
xbps_dbg_printf(xhp, "%s: entry %s changed file "
|
|
|
|
"mode to %s.\n", pkgver, entry_pname,
|
|
|
|
archive_entry_strmode(entry));
|
|
|
|
}
|
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);
|
|
|
|
(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,
|
2013-03-05 08:38:42 +05:30
|
|
|
XBPS_STATE_CONFIG_FILE, 0, pkgver,
|
2011-12-19 15:50:27 +05:30
|
|
|
"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-11-20 01:20:58 +05:30
|
|
|
if (!force && skip_extract) {
|
2012-10-26 13:57:24 +05:30
|
|
|
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,
|
2013-05-15 16:15:35 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%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++;
|
2012-11-30 11:41:51 +05:30
|
|
|
(*xhp->unpack_cb)(&xucd, xhp->unpack_cb_data);
|
2012-10-26 13:57:24 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
2013-05-17 12:47:32 +05:30
|
|
|
/*
|
|
|
|
* XXX: duplicate code.
|
|
|
|
* Create the metaplist file if it wasn't created before.
|
|
|
|
*/
|
|
|
|
if (propsd && filesd && !metafile) {
|
|
|
|
rv = create_pkg_metaplist(xhp, pkgname, pkgver,
|
|
|
|
propsd, filesd, instbuf, instbufsiz,
|
|
|
|
rembuf, rembufsiz);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
rv, pkgver,
|
|
|
|
"%s: [unpack] failed to create metaplist file: %s",
|
|
|
|
pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
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,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver, NULL,
|
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
|
|
|
*/
|
2012-05-26 02:14:58 +05:30
|
|
|
if (skip_obsoletes || preserve || (!softreplace && !update))
|
2013-05-17 11:54:47 +05:30
|
|
|
goto out;
|
2011-11-10 01:31:25 +05:30
|
|
|
/*
|
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
|
|
|
*/
|
2013-03-05 11:12:25 +05:30
|
|
|
old_filesd = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
|
2013-02-05 16:40:24 +05:30
|
|
|
if (old_filesd == NULL)
|
2013-05-17 11:54:47 +05:30
|
|
|
goto out;
|
2012-11-18 16:37:43 +05:30
|
|
|
|
|
|
|
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(obsoletes); i++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
obj = xbps_array_get(obsoletes, i);
|
|
|
|
file = xbps_string_cstring_nocopy(obj);
|
2012-11-18 16:37:43 +05:30
|
|
|
if (remove(file) == -1) {
|
2012-10-24 11:15:00 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
2012-11-18 16:37:43 +05:30
|
|
|
XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
|
2013-03-07 16:22:47 +05:30
|
|
|
errno, pkgver,
|
2012-11-18 16:37:43 +05:30
|
|
|
"%s: failed to remove obsolete entry `%s': %s",
|
|
|
|
pkgver, file, strerror(errno));
|
|
|
|
continue;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-11-18 16:37:43 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
|
|
|
XBPS_STATE_REMOVE_FILE_OBSOLETE,
|
2013-03-07 16:22:47 +05:30
|
|
|
0, pkgver, "%s: removed obsolete entry: %s", pkgver, file);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(obj);
|
2011-11-10 01:31:25 +05:30
|
|
|
}
|
2013-08-29 15:36:04 +05:30
|
|
|
xbps_object_release(old_filesd);
|
2012-11-16 21:25:35 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
out:
|
2013-06-20 13:56:12 +05:30
|
|
|
if (xbps_object_type(filesd) == XBPS_TYPE_DICTIONARY)
|
|
|
|
xbps_object_release(filesd);
|
|
|
|
if (xbps_object_type(propsd) == XBPS_TYPE_DICTIONARY)
|
|
|
|
xbps_object_release(propsd);
|
2013-03-05 11:12:25 +05:30
|
|
|
if (pkgname != NULL)
|
|
|
|
free(pkgname);
|
2013-04-04 13:25:35 +05:30
|
|
|
if (instbuf != NULL)
|
|
|
|
free(instbuf);
|
|
|
|
if (rembuf != NULL)
|
|
|
|
free(rembuf);
|
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
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
2011-12-22 12:53:11 +05:30
|
|
|
struct archive *ar = NULL;
|
2013-08-29 18:00:14 +05:30
|
|
|
struct stat st;
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *pkgver;
|
2013-08-29 18:00:14 +05:30
|
|
|
char *bpkg = NULL;
|
|
|
|
int pkg_fd = -1, rv = 0;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
2013-04-04 13:45:32 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK, 0, pkgver, NULL);
|
2011-11-24 15:53:08 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
bpkg = xbps_repository_pkg_path(xhp, pkg_repod);
|
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,
|
2013-03-05 08:38:42 +05:30
|
|
|
errno, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: [unpack] cannot determine binary package "
|
2012-11-30 11:41:51 +05:30
|
|
|
"file for `%s': %s", pkgver, bpkg, 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);
|
|
|
|
|
2012-12-15 14:21:44 +05:30
|
|
|
pkg_fd = open(bpkg, O_RDONLY|O_CLOEXEC);
|
|
|
|
if (pkg_fd == -1) {
|
2013-08-29 18:00:14 +05:30
|
|
|
rv = errno;
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: [unpack] failed to open binary package `%s': %s",
|
2012-11-30 11:41:51 +05:30
|
|
|
pkgver, bpkg, strerror(rv));
|
2013-08-29 18:00:14 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (fstat(pkg_fd, &st) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
rv, pkgver,
|
|
|
|
"%s: [unpack] failed to fstat binary package `%s': %s",
|
|
|
|
pkgver, bpkg, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (archive_read_open_fd(ar, pkg_fd, st.st_blksize) == ARCHIVE_FATAL) {
|
|
|
|
rv = archive_errno(ar);
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
|
|
|
rv, pkgver,
|
|
|
|
"%s: [unpack] failed to read binary package `%s': %s",
|
|
|
|
pkgver, bpkg, strerror(rv));
|
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
/*
|
|
|
|
* Extract archive files.
|
|
|
|
*/
|
2013-03-05 08:38:42 +05:30
|
|
|
if ((rv = unpack_archive(xhp, pkg_repod, pkgver, bpkg, ar)) != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
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.
|
|
|
|
*/
|
2013-03-05 08:38:42 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_installed(xhp, pkgver,
|
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,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%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:
|
2013-08-29 18:00:14 +05:30
|
|
|
if (pkg_fd != -1)
|
|
|
|
close(pkg_fd);
|
2012-12-15 14:21:44 +05:30
|
|
|
if (ar)
|
2013-08-29 18:00:14 +05:30
|
|
|
archive_read_finish(ar);
|
2013-03-05 08:38:42 +05:30
|
|
|
if (bpkg)
|
|
|
|
free(bpkg);
|
2012-12-15 14:21:44 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
return rv;
|
|
|
|
}
|