2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-21 21:46:58 +05:30
|
|
|
* Copyright (c) 2008-2011 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>
|
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
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
2011-01-19 05:01:22 +05:30
|
|
|
* @file lib/package_unpack.c
|
2010-01-21 07:40:19 +05:30
|
|
|
* @brief Binary package file unpacking routines
|
|
|
|
* @defgroup unpack Binary package file unpacking functions
|
2010-01-23 04:26:39 +05:30
|
|
|
*
|
2010-01-23 10:46:05 +05:30
|
|
|
* Unpacking a binary package involves the following steps:
|
|
|
|
* - Its <b>pre-install</b> target in the INSTALL script is executed
|
|
|
|
* (if available).
|
|
|
|
* - Metadata files are extracted.
|
|
|
|
* - All other kind of files on archive are extracted.
|
|
|
|
* - Handles configuration files by taking care of updating them with
|
|
|
|
* new versions if necessary and to not overwrite modified ones.
|
2010-01-28 20:38:50 +05:30
|
|
|
* - Files from installed package are compared with new package and
|
|
|
|
* obsolete files are removed.
|
2010-01-23 10:46:05 +05:30
|
|
|
* - Finally its state is set to XBPS_PKG_STATE_UNPACKED.
|
|
|
|
*
|
|
|
|
* The following image shown below represents a transaction dictionary
|
2011-02-21 22:27:46 +05:30
|
|
|
* returned by xbps_transaction_prepare():
|
2010-01-23 04:26:39 +05:30
|
|
|
*
|
|
|
|
* @image html images/xbps_transaction_dictionary.png
|
|
|
|
*
|
|
|
|
* Legend:
|
2010-01-23 10:46:05 +05:30
|
|
|
* - <b>Salmon filled box</b>: The transaction dictionary.
|
|
|
|
* - <b>White filled box</b>: mandatory objects.
|
|
|
|
* - <b>Grey filled box</b>: optional objects.
|
|
|
|
* - <b>Green filled box</b>: possible value set in the object, only one of
|
|
|
|
* them is set.
|
2010-01-23 04:26:39 +05:30
|
|
|
*
|
|
|
|
* Text inside of white boxes are the key associated with the object, its
|
|
|
|
* data type is specified on its edge, i.e string, array, integer, dictionary.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
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
|
|
|
|
extract_metafile(struct archive *ar,
|
|
|
|
struct archive_entry *entry,
|
|
|
|
const char *file,
|
|
|
|
const char *pkgname,
|
|
|
|
const char *version,
|
|
|
|
bool exec,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/%s",
|
|
|
|
XBPS_META_PATH, pkgname, file);
|
|
|
|
if (buf == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
archive_entry_set_pathname(entry, buf);
|
|
|
|
free(buf);
|
|
|
|
if (exec)
|
|
|
|
archive_entry_set_perm(entry, 0750);
|
|
|
|
|
|
|
|
if (archive_read_extract(ar, entry, flags) != 0) {
|
|
|
|
if ((rv = archive_errno(ar)) != EEXIST) {
|
|
|
|
xbps_error_printf("failed to extract metadata file `%s'"
|
|
|
|
"for `%s-%s': %s\n", file, pkgname, version,
|
|
|
|
strerror(rv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
remove_metafile(const char *file, const char *pkgname, const char *version)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/%s",
|
2011-03-04 15:18:39 +05:30
|
|
|
XBPS_META_PATH, pkgname, file);
|
2011-01-21 21:46:58 +05:30
|
|
|
if (buf == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
if (unlink(buf) == -1) {
|
|
|
|
if (errno && errno != ENOENT) {
|
|
|
|
xbps_error_printf("failed to remove metadata file "
|
|
|
|
"`%s' while unpacking `%s-%s': %s\n", file,
|
|
|
|
pkgname, version, strerror(errno));
|
|
|
|
free(buf);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute the unpack progress function callback if set and its
|
|
|
|
* private data is also set. It's so sad that
|
|
|
|
* archive_read_set_progress_callback() from libarchive(3) cannot be used
|
|
|
|
* here because sometimes it misses some entries by unknown reasons.
|
|
|
|
*/
|
2011-07-28 19:55:01 +05:30
|
|
|
#define RUN_PROGRESS_CB() \
|
|
|
|
do { \
|
|
|
|
if (xhp->xbps_unpack_cb != NULL) \
|
|
|
|
(*xhp->xbps_unpack_cb)(xhp->xucd); \
|
2011-01-21 21:46:58 +05:30
|
|
|
} while (0)
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
static int
|
2011-01-21 21:46:58 +05:30
|
|
|
unpack_archive(prop_dictionary_t pkg_repod,
|
|
|
|
struct archive *ar,
|
|
|
|
const char *pkgname,
|
2011-01-22 17:10:19 +05:30
|
|
|
const char *version,
|
2011-07-27 20:43:54 +05:30
|
|
|
struct xbps_handle *xhp)
|
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;
|
2011-01-21 21:46:58 +05:30
|
|
|
prop_array_t array;
|
2011-08-01 16:05:47 +05:30
|
|
|
const struct stat *entry_statp;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct archive_entry *entry;
|
2011-01-22 17:10:19 +05:30
|
|
|
size_t nmetadata = 0, entry_idx = 0;
|
2011-02-21 22:12:47 +05:30
|
|
|
const char *entry_pname, *transact;
|
2010-01-23 04:26:39 +05:30
|
|
|
char *buf;
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv, flags;
|
2011-10-30 15:02:56 +05:30
|
|
|
bool preserve, update, replace;
|
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);
|
2011-01-20 07:25:40 +05:30
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(version != NULL);
|
2009-12-02 11:01:03 +05:30
|
|
|
|
2011-01-21 21:46:58 +05:30
|
|
|
preserve = update = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-10-17 16:07:15 +05:30
|
|
|
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
2011-01-21 21:46:58 +05:30
|
|
|
xbps_error_printf("cannot chdir to rootdir for "
|
|
|
|
"`%s-%s': %s\n", pkgname, version, strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
return errno;
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-20 07:25:40 +05:30
|
|
|
prop_dictionary_get_bool(pkg_repod, "preserve", &preserve);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod,
|
2011-02-05 16:51:04 +05:30
|
|
|
"transaction", &transact);
|
2011-01-22 17:10:19 +05:30
|
|
|
assert(transact != NULL);
|
2011-01-20 07:25:40 +05:30
|
|
|
|
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
|
|
|
/*
|
2010-01-23 04:26:39 +05:30
|
|
|
* While updating, always remove current INSTALL/REMOVE
|
|
|
|
* scripts, because a package upgrade might not have those
|
|
|
|
* anymore.
|
2010-01-19 00:19:32 +05:30
|
|
|
*/
|
2010-01-23 04:26:39 +05:30
|
|
|
if (update) {
|
2011-01-21 21:46:58 +05:30
|
|
|
if ((rv = remove_metafile("INSTALL", pkgname, version)) != 0)
|
|
|
|
return rv;
|
|
|
|
if ((rv = remove_metafile("REMOVE", pkgname, version)) != 0)
|
|
|
|
return rv;
|
2010-01-23 04:26:39 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Process the archive files.
|
|
|
|
*/
|
|
|
|
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
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();
|
|
|
|
|
|
|
|
if (xhp->xbps_unpack_cb != NULL) {
|
2011-07-27 20:43:54 +05:30
|
|
|
xhp->xucd->entry = entry_pname;
|
|
|
|
xhp->xucd->entry_size = archive_entry_size(entry);
|
|
|
|
xhp->xucd->entry_is_metadata = false;
|
|
|
|
xhp->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
|
|
|
*/
|
2009-08-17 22:37:20 +05:30
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
|
|
|
XBPS_META_PATH, pkgname);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
rv = extract_metafile(ar, entry, "INSTALL",
|
|
|
|
pkgname, version, true, flags);
|
|
|
|
if (rv != 0) {
|
|
|
|
free(buf);
|
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
rv = xbps_file_exec(buf, "pre",
|
2010-05-18 11:16:27 +05:30
|
|
|
pkgname, version, update ? "yes" : "no", NULL);
|
2011-01-20 07:25:40 +05:30
|
|
|
free(buf);
|
2010-05-18 17:10:51 +05:30
|
|
|
if (rv != 0) {
|
2011-01-21 21:46:58 +05:30
|
|
|
xbps_error_printf("%s-%s: pre-install script "
|
|
|
|
"error: %s\n", pkgname, version,
|
|
|
|
strerror(rv));
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-01-22 17:10:19 +05:30
|
|
|
nmetadata++;
|
2011-07-28 19:55:01 +05:30
|
|
|
xhp->xucd->entry_is_metadata = true;
|
|
|
|
xhp->xucd->entry_extract_count++;
|
2011-01-21 21:46:58 +05:30
|
|
|
RUN_PROGRESS_CB();
|
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) {
|
2011-01-21 21:46:58 +05:30
|
|
|
rv = extract_metafile(ar, entry, "REMOVE",
|
|
|
|
pkgname, version, true, flags);
|
|
|
|
if (rv != 0)
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2011-01-21 21:46:58 +05:30
|
|
|
|
2011-01-22 17:10:19 +05:30
|
|
|
nmetadata++;
|
2011-07-28 19:55:01 +05:30
|
|
|
xhp->xucd->entry_is_metadata = true;
|
|
|
|
xhp->xucd->entry_extract_count++;
|
2011-01-21 21:46:58 +05:30
|
|
|
RUN_PROGRESS_CB();
|
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;
|
|
|
|
}
|
2011-01-22 17:10:19 +05:30
|
|
|
nmetadata++;
|
2011-07-28 19:55:01 +05:30
|
|
|
xhp->xucd->entry_is_metadata = true;
|
|
|
|
xhp->xucd->entry_extract_count++;
|
2011-01-21 21:46:58 +05:30
|
|
|
RUN_PROGRESS_CB();
|
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) {
|
2011-01-21 21:46:58 +05:30
|
|
|
rv = extract_metafile(ar, entry, XBPS_PKGPROPS,
|
|
|
|
pkgname, version, false, flags);
|
|
|
|
if (rv != 0)
|
2010-12-25 07:08:30 +05:30
|
|
|
goto out;
|
2010-01-23 04:26:39 +05:30
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
propsd = xbps_dictionary_from_metadata_plist(
|
2011-01-21 21:46:58 +05:30
|
|
|
pkgname, XBPS_PKGPROPS);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (propsd == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-22 17:10:19 +05:30
|
|
|
nmetadata++;
|
2011-07-28 19:55:01 +05:30
|
|
|
xhp->xucd->entry_is_metadata = true;
|
|
|
|
xhp->xucd->entry_extract_count++;
|
2011-01-21 21:46:58 +05:30
|
|
|
RUN_PROGRESS_CB();
|
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) {
|
|
|
|
xbps_error_printf("invalid binary pkg archive"
|
|
|
|
"for `%s-%s'\n", pkgname, version);
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENODEV;
|
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.
|
2011-01-22 17:10:19 +05:30
|
|
|
* total_entries = metadata + files + conf_files + links.
|
2011-01-21 21:46:58 +05:30
|
|
|
*/
|
2011-07-28 19:55:01 +05:30
|
|
|
xhp->xucd->entry_total_count = nmetadata;
|
|
|
|
array = prop_dictionary_get(filesd, "files");
|
|
|
|
xhp->xucd->entry_total_count +=
|
|
|
|
(ssize_t)prop_array_count(array);
|
|
|
|
array = prop_dictionary_get(filesd, "conf_files");
|
|
|
|
xhp->xucd->entry_total_count +=
|
|
|
|
(ssize_t)prop_array_count(array);
|
|
|
|
array = prop_dictionary_get(filesd, "links");
|
|
|
|
xhp->xucd->entry_total_count +=
|
|
|
|
(ssize_t)prop_array_count(array);
|
2011-01-21 21:46:58 +05:30
|
|
|
|
2011-10-30 15:02:56 +05:30
|
|
|
replace = false;
|
|
|
|
if (prop_dictionary_get_bool(pkg_repod,
|
|
|
|
"replacing-package", &replace) && replace) {
|
|
|
|
/*
|
|
|
|
* The package we are currently unpacking replaced
|
|
|
|
* another package that it was removed, respect
|
|
|
|
* configuration files if they exist.
|
|
|
|
*/
|
|
|
|
if (S_ISREG(entry_statp->st_mode) &&
|
|
|
|
xbps_entry_is_a_conf_file(propsd, entry_pname) &&
|
|
|
|
(access(entry_pname, R_OK) == 0)) {
|
|
|
|
xbps_dbg_printf("%s: preserving conf_file %s.\n",
|
|
|
|
pkgname, entry_pname);
|
|
|
|
archive_read_data_skip(ar);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-08-01 16:05:47 +05:30
|
|
|
if (update && S_ISREG(entry_statp->st_mode)) {
|
|
|
|
/*
|
|
|
|
* Handle configuration files. Check if current entry is
|
|
|
|
* a configuration file and take action if required. Skip
|
|
|
|
* packages that don't have the "conf_files" array in
|
|
|
|
* the XBPS_PKGPROPS dictionary.
|
|
|
|
*/
|
|
|
|
rv = xbps_entry_is_a_conf_file(propsd, entry_pname);
|
2011-01-20 07:25:40 +05:30
|
|
|
if (rv == -1) {
|
|
|
|
/* error */
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2011-08-01 16:05:47 +05:30
|
|
|
} else if (rv == 1) {
|
2011-10-30 15:02:56 +05:30
|
|
|
/* configuration file */
|
2011-08-01 16:05:47 +05:30
|
|
|
if (xhp->xucd != NULL)
|
|
|
|
xhp->xucd->entry_is_conf = true;
|
|
|
|
|
|
|
|
rv = xbps_entry_install_conf_file(filesd,
|
|
|
|
entry, entry_pname, pkgname, version);
|
|
|
|
if (rv == -1) {
|
|
|
|
/* error */
|
|
|
|
goto out;
|
|
|
|
} else if (rv == 0) {
|
|
|
|
/*
|
|
|
|
* Keep current configuration file
|
|
|
|
* as is now and pass to next entry.
|
|
|
|
*/
|
|
|
|
archive_read_data_skip(ar);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-20 07:25:40 +05:30
|
|
|
/*
|
2011-08-01 16:05:47 +05:30
|
|
|
* Current entry is not a configuration file,
|
|
|
|
* check if installed file matches sha256 hash.
|
|
|
|
* If true, there is no need to extract it.
|
2011-01-20 07:25:40 +05:30
|
|
|
*/
|
2011-08-01 16:05:47 +05:30
|
|
|
rv = xbps_file_hash_check_dictionary(filesd,
|
|
|
|
"files", entry_pname);
|
|
|
|
if (rv == -1) {
|
|
|
|
xbps_dbg_printf("%s-%s: failed to check"
|
|
|
|
" hash for `%s': %s\n", pkgname,
|
|
|
|
version, entry_pname,
|
|
|
|
strerror(errno));
|
|
|
|
/* error */
|
|
|
|
goto out;
|
|
|
|
} else if (rv == 0) {
|
|
|
|
/* hash match, skip */
|
2011-10-30 15:02:56 +05:30
|
|
|
xbps_dbg_printf("%s-%s: entry %s "
|
|
|
|
"matches current SHA256, "
|
|
|
|
"skipping...\n", pkgname,
|
|
|
|
version, entry_pname);
|
2011-08-01 16:05:47 +05:30
|
|
|
archive_read_data_skip(ar);
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
|
|
|
}
|
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);
|
2011-01-21 21:46:58 +05:30
|
|
|
if (rv != EEXIST) {
|
|
|
|
xbps_error_printf("failed to extract `%s' "
|
|
|
|
"from `%s-%s': %s\n", entry_pname,
|
|
|
|
pkgname, version, strerror(rv));
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2011-01-21 21:46:58 +05:30
|
|
|
} else {
|
2011-07-05 21:17:37 +05:30
|
|
|
if (xhp->flags & XBPS_FLAG_VERBOSE)
|
|
|
|
xbps_warn_printf("ignoring existing "
|
|
|
|
"entry: %s\n", entry_pname);
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-07-28 19:55:01 +05:30
|
|
|
xhp->xucd->entry_extract_count++;
|
2011-01-21 21:46:58 +05:30
|
|
|
RUN_PROGRESS_CB();
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = archive_errno(ar)) == 0) {
|
2010-11-19 18:10:13 +05:30
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/%s",
|
|
|
|
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
2010-01-23 04:26:39 +05:30
|
|
|
if (buf == NULL) {
|
2010-12-25 07:08:30 +05:30
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
2009-11-09 07:00:04 +05:30
|
|
|
}
|
|
|
|
/*
|
2010-01-28 20:38:50 +05:30
|
|
|
* Check if files.plist exists and pkg is NOT marked as
|
|
|
|
* preserve, in that case we need to check for obsolete files
|
|
|
|
* and remove them if necessary.
|
2009-11-09 07:00:04 +05:30
|
|
|
*/
|
2010-11-19 18:10:13 +05:30
|
|
|
if (!preserve) {
|
2009-11-09 07:00:04 +05:30
|
|
|
old_filesd =
|
2010-04-20 17:52:38 +05:30
|
|
|
prop_dictionary_internalize_from_zfile(buf);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (old_filesd) {
|
|
|
|
rv = xbps_remove_obsoletes(old_filesd, filesd);
|
|
|
|
if (rv != 0) {
|
|
|
|
prop_object_release(old_filesd);
|
|
|
|
free(buf);
|
2010-12-25 07:08:30 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2010-12-25 07:08:30 +05:30
|
|
|
prop_object_release(old_filesd);
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
} else if (errno && errno != ENOENT) {
|
2010-01-23 04:26:39 +05:30
|
|
|
free(buf);
|
2010-12-25 07:08:30 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2009-11-09 07:00:04 +05:30
|
|
|
}
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Now that all files were successfully unpacked, we
|
|
|
|
* can safely externalize files.plist because the path
|
|
|
|
* is reachable.
|
|
|
|
*/
|
2010-04-20 17:52:38 +05:30
|
|
|
if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
|
2010-12-25 07:08:30 +05:30
|
|
|
rv = errno;
|
2011-01-21 21:46:58 +05:30
|
|
|
xbps_error_printf("failed to extract metadata %s file"
|
|
|
|
"for `%s-%s': %s\n", XBPS_PKGFILES, pkgname,
|
|
|
|
version, strerror(rv));
|
|
|
|
free(buf);
|
2010-12-25 07:08:30 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
free(buf);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
|
|
|
|
out:
|
2010-01-19 00:19:32 +05:30
|
|
|
if (filesd)
|
|
|
|
prop_object_release(filesd);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (propsd)
|
|
|
|
prop_object_release(propsd);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
#undef RUN_PROGRESS_CB
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2011-02-21 18:08:44 +05:30
|
|
|
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
2011-07-27 20:43:54 +05:30
|
|
|
struct xbps_handle *xhp;
|
2011-01-21 21:46:58 +05:30
|
|
|
struct archive *ar;
|
2011-07-30 02:58:36 +05:30
|
|
|
const char *pkgname, *version, *repoloc, *pkgver, *fname;
|
2011-01-21 21:46:58 +05:30
|
|
|
char *bpkg;
|
|
|
|
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
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
bpkg = xbps_path_from_repository_uri(pkg_repod, repoloc);
|
2011-01-21 21:46:58 +05:30
|
|
|
if (bpkg == NULL) {
|
|
|
|
xbps_error_printf("cannot determine binary pkg file "
|
|
|
|
"for `%s-%s': %s\n", pkgname, version, strerror(errno));
|
|
|
|
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-01-21 21:46:58 +05:30
|
|
|
rv = ENOMEM;
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Enable support for tar format and all compression methods.
|
|
|
|
*/
|
|
|
|
archive_read_support_compression_all(ar);
|
|
|
|
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);
|
|
|
|
xbps_error_printf("failed to open `%s' binpkg: %s\n",
|
2011-07-30 02:58:36 +05:30
|
|
|
fname, strerror(rv));
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
/*
|
|
|
|
* Set extract progress callback if specified.
|
|
|
|
*/
|
2011-02-21 18:08:44 +05:30
|
|
|
xhp = xbps_handle_get();
|
2011-07-28 19:55:01 +05:30
|
|
|
if (xhp->xbps_unpack_cb != NULL) {
|
2011-07-27 20:43:54 +05:30
|
|
|
xhp->xucd->entry_extract_count = 0;
|
|
|
|
xhp->xucd->entry_total_count = 0;
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2011-07-28 19:55:01 +05:30
|
|
|
/*
|
|
|
|
* Set package state to half-unpacked.
|
|
|
|
*/
|
|
|
|
if ((rv = xbps_set_pkg_state_installed(pkgname, version, pkgver,
|
|
|
|
XBPS_PKG_STATE_HALF_UNPACKED)) != 0) {
|
|
|
|
xbps_error_printf("failed to set `%s' to half-unpacked "
|
|
|
|
"state: %s\n", pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
/*
|
|
|
|
* Extract archive files.
|
|
|
|
*/
|
2011-07-30 02:58:36 +05:30
|
|
|
if ((rv = unpack_archive(pkg_repod, ar, pkgname, version, xhp)) != 0)
|
2010-01-23 04:26:39 +05:30
|
|
|
goto out;
|
2011-07-30 02:58:36 +05:30
|
|
|
|
2010-01-23 04:26:39 +05:30
|
|
|
/*
|
|
|
|
* Set package state to unpacked.
|
|
|
|
*/
|
2011-07-28 19:55:01 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_installed(pkgname, version, pkgver,
|
|
|
|
XBPS_PKG_STATE_UNPACKED)) != 0) {
|
|
|
|
xbps_error_printf("failed to set `%s' to unpacked "
|
|
|
|
"state: %s\n", pkgver, strerror(rv));
|
2011-01-21 21:46:58 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
out:
|
2011-01-21 21:46:58 +05:30
|
|
|
if (bpkg)
|
|
|
|
free(bpkg);
|
2010-01-21 07:40:19 +05:30
|
|
|
if (ar)
|
|
|
|
archive_read_finish(ar);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|