2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2010-01-19 00:19:32 +05:30
|
|
|
* Copyright (c) 2008-2010 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
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
|
|
|
/**
|
|
|
|
* @file lib/unpack.c
|
|
|
|
* @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
|
|
|
|
* returned by xbps_repository_get_transaction_dict():
|
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
|
|
|
|
|
|
|
static void
|
2010-01-28 20:51:08 +05:30
|
|
|
set_extract_flags(int *flags, bool update)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2010-01-28 20:51:08 +05:30
|
|
|
int lflags = 0;
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
if (getuid() == 0)
|
2010-01-28 20:51:08 +05:30
|
|
|
lflags = FEXTRACT_FLAGS;
|
2009-08-17 22:37:20 +05:30
|
|
|
else
|
2010-01-28 20:51:08 +05:30
|
|
|
lflags = EXTRACT_FLAGS;
|
|
|
|
|
|
|
|
if (!update) {
|
|
|
|
/*
|
|
|
|
* Only overwrite files while updating.
|
|
|
|
*/
|
|
|
|
lflags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
|
|
|
|
lflags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*flags = lflags;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: remove printfs and return appropiate errors to be interpreted by
|
|
|
|
* the consumer.
|
|
|
|
*/
|
|
|
|
static int
|
2010-11-19 18:10:13 +05:30
|
|
|
unpack_archive_fini(struct archive *ar,
|
|
|
|
prop_dictionary_t pkg,
|
|
|
|
const char *pkgname,
|
|
|
|
const char *version)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2010-11-19 18:10:13 +05:30
|
|
|
prop_dictionary_t propsd, filesd, old_filesd;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct archive_entry *entry;
|
2009-12-07 11:54:22 +05:30
|
|
|
size_t entry_idx = 0;
|
2010-11-06 11:14:00 +05:30
|
|
|
const char *rootdir, *entry_str, *transact;
|
2010-01-23 04:26:39 +05:30
|
|
|
char *buf;
|
2010-04-29 03:00:56 +05:30
|
|
|
int rv, flags, lflags;
|
2010-10-23 21:39:35 +05:30
|
|
|
bool preserve, skip_entry, update, replace_files_in_pkg_update;
|
2009-12-07 11:54:22 +05:30
|
|
|
bool props_plist_found, files_plist_found;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
assert(ar != NULL);
|
|
|
|
assert(pkg != NULL);
|
2009-12-02 11:01:03 +05:30
|
|
|
|
2010-10-23 21:39:35 +05:30
|
|
|
preserve = skip_entry = update = replace_files_in_pkg_update = false;
|
2009-12-07 11:54:22 +05:30
|
|
|
props_plist_found = files_plist_found = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
rootdir = xbps_get_rootdir();
|
|
|
|
flags = xbps_get_flags();
|
|
|
|
|
|
|
|
if (chdir(rootdir) == -1)
|
|
|
|
return errno;
|
|
|
|
|
2009-12-02 11:01:03 +05:30
|
|
|
prop_dictionary_get_bool(pkg, "preserve", &preserve);
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg, "trans-action", &transact);
|
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) {
|
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
if (unlink(buf) == -1) {
|
2010-11-19 18:10:13 +05:30
|
|
|
if (errno && errno != ENOENT) {
|
2010-01-23 04:26:39 +05:30
|
|
|
free(buf);
|
2010-01-19 00:19:32 +05:30
|
|
|
return errno;
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
if (unlink(buf) == -1) {
|
2010-11-19 18:10:13 +05:30
|
|
|
if (errno && errno != ENOENT) {
|
2010-01-23 04:26:39 +05:30
|
|
|
free(buf);
|
2010-01-19 00:19:32 +05:30
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
free(buf);
|
|
|
|
}
|
2010-01-19 00:19:32 +05:30
|
|
|
|
2010-01-23 04:26:39 +05:30
|
|
|
/*
|
|
|
|
* Process the archive files.
|
|
|
|
*/
|
|
|
|
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
|
|
|
entry_str = archive_entry_pathname(entry);
|
2010-01-28 20:51:08 +05:30
|
|
|
set_extract_flags(&lflags, update);
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Run the pre INSTALL action if the file is there.
|
|
|
|
*/
|
2009-10-21 21:46:17 +05:30
|
|
|
if (strcmp("./INSTALL", entry_str) == 0) {
|
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;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
archive_entry_set_pathname(entry, buf);
|
2010-11-19 18:10:13 +05:30
|
|
|
archive_entry_set_perm(entry, 0750);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-09-30 21:59:21 +05:30
|
|
|
if (archive_read_extract(ar, entry, lflags) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
if ((rv = archive_errno(ar)) != EEXIST) {
|
|
|
|
free(buf);
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
2009-12-09 20:44:35 +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);
|
2010-05-18 17:10:51 +05:30
|
|
|
if (rv != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
free(buf);
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr,
|
|
|
|
"%s: preinst action target error %s\n",
|
2009-08-17 22:37:20 +05:30
|
|
|
pkgname, strerror(errno));
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
/* Pass to the next entry if successful */
|
2009-08-17 22:37:20 +05:30
|
|
|
free(buf);
|
2009-12-07 11:54:22 +05:30
|
|
|
entry_idx++;
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpack metadata files in final directory.
|
|
|
|
*/
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if (strcmp("./REMOVE", entry_str) == 0) {
|
2010-01-23 04:26:39 +05:30
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE",
|
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;
|
|
|
|
}
|
|
|
|
|
2010-01-23 04:26:39 +05:30
|
|
|
archive_entry_set_pathname(entry, buf);
|
|
|
|
free(buf);
|
2010-11-19 18:10:13 +05:30
|
|
|
archive_entry_set_perm(entry, 0750);
|
|
|
|
if (archive_read_extract(ar, entry, lflags) != 0) {
|
|
|
|
if ((rv = archive_errno(ar)) != EEXIST)
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
|
|
|
|
/* Pass to next entry if successful */
|
|
|
|
entry_idx++;
|
|
|
|
continue;
|
2009-12-11 15:28:46 +05:30
|
|
|
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if (strcmp("./files.plist", entry_str) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Now we have a dictionary from the entry
|
|
|
|
* in memory. Will be written to disk later, when
|
|
|
|
* all files are extracted.
|
|
|
|
*/
|
|
|
|
filesd = xbps_read_dict_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
|
|
|
|
|
|
|
/* Pass to next entry */
|
2009-12-07 11:54:22 +05:30
|
|
|
files_plist_found = true;
|
|
|
|
entry_idx++;
|
2009-08-17 22:37:20 +05:30
|
|
|
continue;
|
|
|
|
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if (strcmp("./props.plist", entry_str) == 0) {
|
2010-11-19 18:10:13 +05:30
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/%s",
|
|
|
|
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
|
|
|
if (buf == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-01-23 04:26:39 +05:30
|
|
|
archive_entry_set_pathname(entry, buf);
|
|
|
|
free(buf);
|
|
|
|
|
2010-12-25 07:08:30 +05:30
|
|
|
if (archive_read_extract(ar, entry, lflags) != 0) {
|
|
|
|
rv = archive_errno(ar);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
propsd =
|
|
|
|
xbps_get_pkg_dict_from_metadata_plist(pkgname,
|
|
|
|
XBPS_PKGPROPS);
|
|
|
|
if (propsd == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-23 04:26:39 +05:30
|
|
|
/* Pass to next entry if successful */
|
2009-12-07 11:54:22 +05:30
|
|
|
props_plist_found = true;
|
2010-01-23 04:26:39 +05:30
|
|
|
entry_idx++;
|
|
|
|
continue;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-10-21 21:46:17 +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.
|
|
|
|
*/
|
|
|
|
if (!files_plist_found || !props_plist_found) {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (entry_idx >= 3)
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENODEV;
|
2010-01-23 04:26:39 +05:30
|
|
|
|
|
|
|
entry_idx++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (prop_dictionary_get(propsd, "conf_files")) {
|
|
|
|
if ((rv = xbps_config_file_from_archive_entry(filesd,
|
2010-12-25 07:08:30 +05:30
|
|
|
propsd, entry, &lflags, &skip_entry)) != 0)
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2010-12-25 07:08:30 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if (skip_entry) {
|
|
|
|
archive_read_data_skip(ar);
|
|
|
|
skip_entry = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-23 21:39:35 +05:30
|
|
|
/*
|
|
|
|
* Account for the following scenario (real example):
|
|
|
|
*
|
|
|
|
* - gtk+-2.20 is currently installed.
|
|
|
|
* - gtk+-2.20 contains libgdk_pixbuf.so.
|
|
|
|
* - gtk+-2.20 will be updated to 2.22 in the transaction.
|
|
|
|
* - gtk+-2.22 depends on gdk-pixbuf>=2.22.
|
|
|
|
* - gdk-pixbuf-2.22 contains libgdk_pixbuf.so.
|
|
|
|
* - gdk-pixbuf-2.22 will be installed in the transaction.
|
|
|
|
*
|
|
|
|
* We do the following to fix this:
|
|
|
|
*
|
|
|
|
* - gdk-pixbuf-2.22 installs its files overwritting
|
|
|
|
* current ones if they exist.
|
|
|
|
* - gtk+ is updated to 2.22, it checks for obsolete files
|
|
|
|
* and detects that the files that were owned in 2.20
|
|
|
|
* don't match the SHA256 hash and skips them.
|
|
|
|
*/
|
|
|
|
replace_files_in_pkg_update = false;
|
|
|
|
prop_dictionary_get_bool(pkg, "replace-files-in-pkg-update",
|
|
|
|
&replace_files_in_pkg_update);
|
|
|
|
if (replace_files_in_pkg_update) {
|
|
|
|
lflags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE;
|
|
|
|
lflags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Extract entry from archive.
|
|
|
|
*/
|
2009-09-30 21:59:21 +05:30
|
|
|
if (archive_read_extract(ar, entry, lflags) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = archive_errno(ar);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rv && rv != EEXIST) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "ERROR: %s...exiting!\n",
|
2009-08-17 22:37:20 +05:30
|
|
|
archive_error_string(ar));
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
} else if (rv == EEXIST) {
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: ignoring existent "
|
2009-08-17 22:37:20 +05:30
|
|
|
"path: %s\n",
|
|
|
|
archive_entry_pathname(entry));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf(" %s\n", archive_entry_pathname(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-23 04:26:39 +05:30
|
|
|
free(buf);
|
2010-12-25 07:08:30 +05:30
|
|
|
rv = errno;
|
|
|
|
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;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
int
|
|
|
|
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
|
|
|
{
|
2011-01-18 22:51:55 +05:30
|
|
|
const char *pkgname, *version;
|
2010-01-21 07:40:19 +05:30
|
|
|
struct archive *ar = NULL;
|
|
|
|
char *binfile = NULL;
|
|
|
|
int pkg_fd, rv = 0;
|
|
|
|
|
|
|
|
assert(pkg != NULL);
|
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
|
|
|
|
2011-01-18 22:51:55 +05:30
|
|
|
binfile = xbps_get_binpkg_repo_uri(pkg);
|
2010-01-21 07:40:19 +05:30
|
|
|
if (binfile == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if ((pkg_fd = open(binfile, O_RDONLY)) == -1) {
|
|
|
|
rv = errno;
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_dbg_printf("cannot open '%s' for unpacking %s\n",
|
|
|
|
binfile, strerror(errno));
|
2011-01-18 22:51:55 +05:30
|
|
|
free(binfile);
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-01-18 22:51:55 +05:30
|
|
|
free(binfile);
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
ar = archive_read_new();
|
|
|
|
if (ar == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable support for tar format and all compression methods.
|
|
|
|
*/
|
|
|
|
archive_read_support_compression_all(ar);
|
|
|
|
archive_read_support_format_tar(ar);
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if (archive_read_open_fd(ar, pkg_fd,
|
|
|
|
ARCHIVE_READ_BLOCKSIZE) != 0) {
|
|
|
|
rv = errno;
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
if ((rv = unpack_archive_fini(ar, pkg, pkgname, version)) != 0)
|
2010-01-23 04:26:39 +05:30
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set package state to unpacked.
|
|
|
|
*/
|
|
|
|
rv = xbps_set_pkg_state_installed(pkgname, XBPS_PKG_STATE_UNPACKED);
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
out:
|
|
|
|
if (ar)
|
|
|
|
archive_read_finish(ar);
|
|
|
|
if (pkg_fd != -1)
|
|
|
|
(void)close(pkg_fd);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|