New pkg metadata structure for 0.18. See the NEWS file for info.
This commit is contained in:
@@ -44,6 +44,7 @@ EXTOBJS += external/mkpath.o
|
||||
OBJS = package_configure.o package_config_files.o package_orphans.o
|
||||
OBJS += package_remove.o package_remove_obsoletes.o package_state.o
|
||||
OBJS += package_unpack.o package_requiredby.o package_register.o
|
||||
OBJS += package_script.o
|
||||
OBJS += transaction_commit.o transaction_package_replace.o
|
||||
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o
|
||||
OBJS += download.o initend.o pkgdb.o package_conflicts.o
|
||||
|
@@ -91,11 +91,12 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
xbps_dbg_printf(xhp, "%s-%s: processing conf_file %s\n",
|
||||
pkgname, version, entry_pname);
|
||||
|
||||
forigd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
|
||||
forigd = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
if (forigd == NULL) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not currently "
|
||||
"installed\n", pkgname, version, entry_pname);
|
||||
rv = 1;
|
||||
prop_object_release(forigd);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@@ -77,9 +77,8 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
bool update,
|
||||
bool flush)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_dictionary_t pkgd, pkgmetad;
|
||||
const char *version, *pkgver;
|
||||
char *buf;
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
@@ -111,39 +110,19 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
|
||||
XBPS_META_PATH, pkgname);
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
pkgmetad = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
assert(pkgmetad);
|
||||
|
||||
rv = xbps_pkg_exec_script(xhp, pkgmetad, "install-script", "post", update);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [configure] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, xhp->rootdir, strerror(errno));
|
||||
free(buf);
|
||||
return EINVAL;
|
||||
"%s: [configure] INSTALL script failed to execute "
|
||||
"the post ACTION: %s", pkgver, strerror(rv));
|
||||
prop_object_release(pkgmetad);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (access(buf, X_OK) == 0) {
|
||||
if (xbps_file_exec(xhp, buf, "post",
|
||||
pkgname, version, update ? "yes" : "no",
|
||||
xhp->conffile, NULL) != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [configure] INSTALL script failed to execute "
|
||||
"the post ACTION: %s", pkgver, strerror(errno));
|
||||
free(buf);
|
||||
return errno;
|
||||
}
|
||||
} else {
|
||||
if (errno != ENOENT) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [configure] INSTALL script cannot be "
|
||||
"executed: %s", pkgver, strerror(errno));
|
||||
free(buf);
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
prop_object_release(pkgmetad);
|
||||
|
||||
if (state == XBPS_PKG_STATE_INSTALLED)
|
||||
return rv;
|
||||
|
@@ -49,6 +49,7 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
time_t t;
|
||||
struct tm *tmp;
|
||||
const char *pkgname, *version, *desc, *pkgver;
|
||||
char *buf, *sha256;
|
||||
int rv = 0;
|
||||
bool autoinst = false;
|
||||
|
||||
@@ -156,6 +157,15 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Create a hash for the pkg's metafile.
|
||||
*/
|
||||
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
sha256 = xbps_file_hash(buf);
|
||||
assert(sha256);
|
||||
prop_dictionary_set_cstring(pkgd, "metafile-sha256", sha256);
|
||||
free(sha256);
|
||||
free(buf);
|
||||
/*
|
||||
* Remove unneeded objs from pkg dictionary.
|
||||
*/
|
||||
|
@@ -52,7 +52,7 @@
|
||||
* -# Its state will be changed to XBPS_PKG_STATE_HALF_REMOVED.
|
||||
* -# Its <b>purge-remove</b> target specified in the REMOVE script
|
||||
* will be executed.
|
||||
* -# Its package metadata directory will be removed.
|
||||
* -# Its package metadata file will be removed.
|
||||
* -# Package will be unregistered from package database.
|
||||
*
|
||||
* @note
|
||||
@@ -73,50 +73,6 @@
|
||||
* 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.
|
||||
*/
|
||||
static int
|
||||
remove_pkg_metadata(struct xbps_handle *xhp,
|
||||
const char *pkgname,
|
||||
const char *version,
|
||||
const char *pkgver)
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
char *metadir, *path;
|
||||
int rv = 0;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
|
||||
metadir = xbps_xasprintf("%s/%s/metadata/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, pkgname);
|
||||
dirp = opendir(metadir);
|
||||
if (dirp == NULL) {
|
||||
free(metadir);
|
||||
return errno;
|
||||
}
|
||||
|
||||
while ((dp = readdir(dirp)) != NULL) {
|
||||
if ((strcmp(dp->d_name, ".") == 0) ||
|
||||
(strcmp(dp->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
path = xbps_xasprintf("%s/%s", metadir, dp->d_name);
|
||||
if (unlink(path) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_PURGE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [purge] failed to remove metafile `%s': %s",
|
||||
pkgver, path, strerror(errno));
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
(void)closedir(dirp);
|
||||
rv = rmdir(metadir);
|
||||
free(metadir);
|
||||
if (rv != 0)
|
||||
rv = errno;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
prop_dictionary_t dict,
|
||||
@@ -154,6 +110,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
curobj = "directory";
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
version = xbps_pkg_version(pkgver);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
@@ -244,8 +201,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
free(path);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (pkgname)
|
||||
free(pkgname);
|
||||
free(pkgname);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -258,26 +214,22 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
bool soft_replace)
|
||||
{
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
char *tmpname, *buf, *pkgver = NULL;
|
||||
char *tmpname, *buf = NULL, *pkgver = NULL;
|
||||
const char *tmpver = NULL;
|
||||
int rv = 0;
|
||||
bool rmfile_exists = false;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(version != NULL);
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s/REMOVE",
|
||||
XBPS_META_PATH, pkgname);
|
||||
|
||||
pkgver = xbps_xasprintf("%s-%s", pkgname, version);
|
||||
|
||||
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0)
|
||||
goto out;
|
||||
|
||||
if (!update)
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
|
||||
|
||||
pkgver = xbps_xasprintf("%s-%s", pkgname, version);
|
||||
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
rv = errno;
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
@@ -286,34 +238,24 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
pkgver, xhp->rootdir, strerror(rv));
|
||||
goto out;
|
||||
}
|
||||
pkgd = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
assert(pkgd);
|
||||
|
||||
/* If package was "half-removed", remove it fully. */
|
||||
if (state == XBPS_PKG_STATE_HALF_REMOVED)
|
||||
goto purge;
|
||||
/*
|
||||
* Run the pre remove action.
|
||||
*/
|
||||
if (access(buf, X_OK) == 0) {
|
||||
rmfile_exists = true;
|
||||
if (xbps_file_exec(xhp, buf, "pre", pkgname, version,
|
||||
update ? "yes" : "no", xhp->conffile, NULL) != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [remove] REMOVE script failed to "
|
||||
"execute pre ACTION: %s",
|
||||
pkgver, strerror(errno));
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
if (errno != ENOENT) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [remove] REMOVE script failed to "
|
||||
"execute pre ACTION: %s",
|
||||
pkgver, strerror(errno));
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
rv = xbps_pkg_exec_script(xhp, pkgd, "remove", "pre", update);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [remove] REMOVE script failed to "
|
||||
"execute pre ACTION: %s",
|
||||
pkgver, strerror(errno));
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* If updating a package, we just need to execute the current
|
||||
@@ -322,7 +264,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
*/
|
||||
if (update) {
|
||||
free(pkgver);
|
||||
free(buf);
|
||||
prop_object_release(pkgd);
|
||||
return xbps_requiredby_pkg_remove(xhp, pkgname);
|
||||
} else if (soft_replace) {
|
||||
/*
|
||||
@@ -333,7 +275,6 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
goto softreplace;
|
||||
}
|
||||
|
||||
pkgd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
|
||||
if (pkgd) {
|
||||
/* Remove regular files */
|
||||
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0)
|
||||
@@ -352,9 +293,8 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
* Execute the post REMOVE action if file exists and we aren't
|
||||
* updating the package.
|
||||
*/
|
||||
if (rmfile_exists &&
|
||||
((rv = xbps_file_exec(xhp, buf, "post", pkgname, version, "no",
|
||||
xhp->conffile, NULL)) != 0)) {
|
||||
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: [remove] REMOVE script failed to execute "
|
||||
@@ -390,26 +330,27 @@ purge:
|
||||
/*
|
||||
* Execute the purge REMOVE action if file exists.
|
||||
*/
|
||||
if (access(buf, X_OK) == 0) {
|
||||
if ((rv = xbps_file_exec(xhp, buf, "purge", pkgname, version, "no",
|
||||
xhp->conffile, NULL)) != 0) {
|
||||
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: REMOVE script failed to execute "
|
||||
"purge ACTION: %s", pkgver, strerror(rv));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Remove package metadata directory.
|
||||
* Remove package metadata plist.
|
||||
*/
|
||||
rv = remove_pkg_metadata(xhp, pkgname, version, pkgver);
|
||||
if (rv != 0) {
|
||||
prop_object_release(pkgd);
|
||||
pkgd = NULL;
|
||||
|
||||
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
if (remove(buf) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: failed to remove metadata files: %s",
|
||||
pkgver, strerror(rv));
|
||||
if (rv != ENOENT)
|
||||
"%s: failed to remove metadata file: %s",
|
||||
pkgver, strerror(errno));
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
|
121
lib/package_script.c
Normal file
121
lib/package_script.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* 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 "xbps_api_impl.h"
|
||||
|
||||
int
|
||||
xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
const void *blob,
|
||||
const size_t blobsiz,
|
||||
const char *pkgname,
|
||||
const char *version,
|
||||
const char *action,
|
||||
bool update)
|
||||
{
|
||||
ssize_t ret;
|
||||
const char *tmpdir;
|
||||
char *fpath;
|
||||
int fd, rv;
|
||||
|
||||
assert(blob);
|
||||
assert(pkgname);
|
||||
assert(version);
|
||||
assert(action);
|
||||
|
||||
tmpdir = getenv("TMPDIR");
|
||||
if (tmpdir == NULL)
|
||||
tmpdir = P_tmpdir;
|
||||
|
||||
fpath = xbps_xasprintf("%s/.xbps-script-XXXXXX", tmpdir);
|
||||
|
||||
/* Create temp file to run script */
|
||||
if ((fd = mkstemp(fpath)) == -1) {
|
||||
xbps_dbg_printf(xhp, "%s: mkstemp %s\n",
|
||||
__func__, strerror(errno));
|
||||
free(fpath);
|
||||
return errno;
|
||||
}
|
||||
/* write blob to our temp fd */
|
||||
ret = write(fd, blob, blobsiz);
|
||||
if (ret == -1) {
|
||||
xbps_dbg_printf(xhp, "%s: write %s\n",
|
||||
__func__, strerror(errno));
|
||||
close(fd);
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
fchmod(fd, 0750);
|
||||
fdatasync(fd);
|
||||
close(fd);
|
||||
|
||||
/* change cwd to rootdir to exec the script */
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* exec script */
|
||||
rv = xbps_file_exec(xhp, fpath, action, pkgname, version,
|
||||
update ? "yes" : "no",
|
||||
xhp->conffile, NULL);
|
||||
|
||||
out:
|
||||
remove(fpath);
|
||||
free(fpath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_pkg_exec_script(struct xbps_handle *xhp,
|
||||
prop_dictionary_t d,
|
||||
const char *script,
|
||||
const char *action,
|
||||
bool update)
|
||||
{
|
||||
prop_data_t data;
|
||||
const char *pkgname, *version;
|
||||
|
||||
assert(xhp);
|
||||
assert(d);
|
||||
assert(script);
|
||||
assert(action);
|
||||
|
||||
data = prop_dictionary_get(d, script);
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(d, "version", &version);
|
||||
|
||||
return xbps_pkg_exec_buffer(xhp, prop_data_data(data),
|
||||
prop_data_size(data), pkgname, version,
|
||||
action, update);
|
||||
}
|
@@ -48,104 +48,6 @@ set_extract_flags(uid_t euid)
|
||||
return flags;
|
||||
}
|
||||
|
||||
static int
|
||||
extract_metafile(struct xbps_handle *xhp,
|
||||
struct archive *ar,
|
||||
struct archive_entry *entry,
|
||||
const char *file,
|
||||
const char *pkgver,
|
||||
bool exec,
|
||||
int flags)
|
||||
{
|
||||
const char *version;
|
||||
char *buf, *dirc, *dname, *pkgname;
|
||||
int rv;
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
if (pkgname == NULL)
|
||||
return ENOMEM;
|
||||
version = xbps_pkg_version(pkgver);
|
||||
if (version == NULL) {
|
||||
free(pkgname);
|
||||
return ENOMEM;
|
||||
}
|
||||
buf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, file);
|
||||
archive_entry_set_pathname(entry, buf);
|
||||
dirc = strdup(buf);
|
||||
if (dirc == NULL) {
|
||||
free(buf);
|
||||
free(pkgname);
|
||||
return ENOMEM;
|
||||
}
|
||||
free(buf);
|
||||
dname = dirname(dirc);
|
||||
if (access(dname, X_OK) == -1) {
|
||||
if (xbps_mkpath(dname, 0755) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [unpack] failed to create metadir `%s': %s",
|
||||
pkgver, dname, strerror(errno));
|
||||
free(dirc);
|
||||
free(pkgname);
|
||||
return errno;
|
||||
|
||||
}
|
||||
}
|
||||
if (exec)
|
||||
archive_entry_set_perm(entry, 0750);
|
||||
|
||||
if (archive_read_extract(ar, entry, flags) != 0) {
|
||||
rv = archive_errno(ar);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: [unpack] failed to extract metafile `%s': %s",
|
||||
pkgver, file, strerror(rv));
|
||||
free(dirc);
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
free(pkgname);
|
||||
free(dirc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
remove_metafile(struct xbps_handle *xhp,
|
||||
const char *file,
|
||||
const char *pkgver)
|
||||
{
|
||||
const char *version;
|
||||
char *buf, *pkgname;
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
if (pkgname == NULL)
|
||||
return ENOMEM;
|
||||
version = xbps_pkg_version(pkgver);
|
||||
if (version == NULL) {
|
||||
free(pkgname);
|
||||
return ENOMEM;
|
||||
}
|
||||
buf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, file);
|
||||
if (unlink(buf) == -1) {
|
||||
if (errno && errno != ENOENT) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [unpack] failed to remove metafile `%s': %s",
|
||||
pkgver, file, strerror(errno));
|
||||
free(pkgname);
|
||||
free(buf);
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
free(pkgname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
find_pkg_symlink_target(prop_dictionary_t d, const char *file)
|
||||
{
|
||||
@@ -181,14 +83,18 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
prop_dictionary_t filesd, old_filesd;
|
||||
prop_array_t array, obsoletes;
|
||||
prop_object_t obj;
|
||||
prop_data_t data;
|
||||
void *instbuf, *rembuf;
|
||||
const struct stat *entry_statp;
|
||||
struct stat st;
|
||||
struct xbps_unpack_cb_data xucd;
|
||||
struct archive_entry *entry;
|
||||
size_t i, entry_idx = 0;
|
||||
size_t instbufsiz, rembufsiz;
|
||||
ssize_t entry_size;
|
||||
const char *file, *entry_pname, *transact, *pkgname;
|
||||
const char *version, *pkgver, *fname, *tgtlnk;
|
||||
char *dname, *buf, *buf2, *p, *p2, *pkgfilesd, *pkgpropsd;
|
||||
char *dname, *buf, *buf2, *p, *p2;
|
||||
int ar_rv, rv, rv_stat, flags;
|
||||
bool preserve, update, conf_file, file_exists, skip_obsoletes;
|
||||
bool softreplace, skip_extract;
|
||||
@@ -197,8 +103,8 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
||||
assert(ar != NULL);
|
||||
|
||||
instbuf = rembuf = NULL;
|
||||
filesd = old_filesd = NULL;
|
||||
pkgfilesd = pkgpropsd = NULL;
|
||||
preserve = update = conf_file = file_exists = false;
|
||||
skip_obsoletes = softreplace = false;
|
||||
|
||||
@@ -238,15 +144,6 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
}
|
||||
if (strcmp(transact, "update") == 0)
|
||||
update = true;
|
||||
/*
|
||||
* Always remove current INSTALL/REMOVE scripts in pkg's metadir,
|
||||
* as security measures.
|
||||
*/
|
||||
if ((rv = remove_metafile(xhp, "INSTALL", pkgver)) != 0)
|
||||
goto out;
|
||||
if ((rv = remove_metafile(xhp, "REMOVE", pkgver)) != 0)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Process the archive files.
|
||||
*/
|
||||
@@ -259,6 +156,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
|
||||
entry_statp = archive_entry_stat(entry);
|
||||
entry_pname = archive_entry_pathname(entry);
|
||||
entry_size = archive_entry_size(entry);
|
||||
flags = set_extract_flags(euid);
|
||||
/*
|
||||
* Ignore directories from archive.
|
||||
@@ -273,26 +171,27 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (xhp->unpack_cb != NULL) {
|
||||
xucd.pkgver = pkgver;
|
||||
xucd.entry = entry_pname;
|
||||
xucd.entry_size = archive_entry_size(entry);
|
||||
xucd.entry_size = entry_size;
|
||||
xucd.entry_is_conf = false;
|
||||
}
|
||||
if (strcmp("./INSTALL", entry_pname) == 0) {
|
||||
/*
|
||||
* Extract the INSTALL script first to execute
|
||||
* the pre install target.
|
||||
* Store file in a buffer and execute
|
||||
* the "pre" action from it.
|
||||
*/
|
||||
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
|
||||
XBPS_META_PATH, pkgname);
|
||||
rv = extract_metafile(xhp, ar, entry,
|
||||
"INSTALL", pkgver, true, flags);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
instbufsiz = entry_size;
|
||||
instbuf = malloc(entry_size);
|
||||
assert(instbuf);
|
||||
|
||||
rv = xbps_file_exec(xhp, buf, "pre",
|
||||
pkgname, version, update ? "yes" : "no",
|
||||
xhp->conffile, NULL);
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
if (archive_read_data(ar, instbuf, entry_size) !=
|
||||
entry_size) {
|
||||
rv = EINVAL;
|
||||
free(instbuf);
|
||||
goto out;
|
||||
}
|
||||
|
||||
rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz,
|
||||
pkgname, version, "pre", update);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_UNPACK_FAIL,
|
||||
@@ -300,16 +199,22 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
"%s: [unpack] INSTALL script failed "
|
||||
"to execute pre ACTION: %s",
|
||||
pkgver, strerror(rv));
|
||||
free(instbuf);
|
||||
goto out;
|
||||
}
|
||||
continue;
|
||||
|
||||
} else if (strcmp("./REMOVE", entry_pname) == 0) {
|
||||
rv = extract_metafile(xhp, ar, entry,
|
||||
"REMOVE", pkgver, true, flags);
|
||||
if (rv != 0)
|
||||
/* 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;
|
||||
free(rembuf);
|
||||
goto out;
|
||||
|
||||
}
|
||||
continue;
|
||||
|
||||
} else if (strcmp("./files.plist", entry_pname) == 0) {
|
||||
@@ -571,8 +476,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
* - Package with "preserve" keyword.
|
||||
* - Package with "skip-obsoletes" keyword.
|
||||
*/
|
||||
pkgfilesd = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
||||
|
||||
if (skip_obsoletes || preserve || (!softreplace && !update))
|
||||
goto out1;
|
||||
/*
|
||||
@@ -580,7 +484,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
* - Package upgrade.
|
||||
* - Package with "softreplace" keyword.
|
||||
*/
|
||||
old_filesd = prop_dictionary_internalize_from_zfile(pkgfilesd);
|
||||
old_filesd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
|
||||
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) {
|
||||
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
|
||||
for (i = 0; i < prop_array_count(obsoletes); i++) {
|
||||
@@ -600,60 +504,66 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
"%s: removed obsolete entry: %s", pkgver, file);
|
||||
prop_object_release(obj);
|
||||
}
|
||||
prop_object_release(old_filesd);
|
||||
}
|
||||
out1:
|
||||
/*
|
||||
* Create pkg metadata directory if doesn't exist.
|
||||
*/
|
||||
buf = xbps_xasprintf("%s/metadata/%s", XBPS_META_PATH, pkgname);
|
||||
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;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
/*
|
||||
* Externalize XBPS_PKGFILES into pkg's metadir.
|
||||
*/
|
||||
if (!prop_dictionary_externalize_to_file(filesd, pkgfilesd)) {
|
||||
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_PKGFILES, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
out1:
|
||||
/* Add objects from XBPS_PKGFILES */
|
||||
array = prop_dictionary_get(filesd, "files");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(pkg_repod, "files", array);
|
||||
array = prop_dictionary_get(filesd, "conf_files");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(pkg_repod, "conf_files", array);
|
||||
array = prop_dictionary_get(filesd, "links");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(pkg_repod, "links", array);
|
||||
array = prop_dictionary_get(filesd, "dirs");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(pkg_repod, "dirs", array);
|
||||
|
||||
/* Add install/remove scripts data objects */
|
||||
if (instbuf != NULL) {
|
||||
data = prop_data_create_data(instbuf, instbufsiz);
|
||||
assert(data);
|
||||
prop_dictionary_set(pkg_repod, "install-script", data);
|
||||
prop_object_release(data);
|
||||
free(instbuf);
|
||||
}
|
||||
if (rembuf != NULL) {
|
||||
data = prop_data_create_data(rembuf, rembufsiz);
|
||||
assert(data);
|
||||
prop_dictionary_set(pkg_repod, "remove-script", data);
|
||||
prop_object_release(data);
|
||||
free(rembuf);
|
||||
}
|
||||
/* Remove unneeded objs from transaction */
|
||||
prop_dictionary_remove(pkg_repod, "remove-and-update");
|
||||
prop_dictionary_remove(pkg_repod, "transaction");
|
||||
prop_dictionary_remove(pkg_repod, "state");
|
||||
|
||||
/*
|
||||
* Externalize XBPS_PKGPROPS into pkg's metadir.
|
||||
* Externalize pkg dictionary to metadir.
|
||||
*/
|
||||
pkgpropsd = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
||||
if (!prop_dictionary_externalize_to_file(pkg_repod, pkgpropsd)) {
|
||||
if (access(xhp->metadir, R_OK|X_OK) == -1) {
|
||||
if (errno == ENOENT) {
|
||||
xbps_mkpath(xhp->metadir, 0755);
|
||||
} else {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
buf = xbps_xasprintf("%s/.%s.plist", XBPS_META_PATH, pkgname);
|
||||
if (!prop_dictionary_externalize_to_file(pkg_repod, buf)) {
|
||||
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));
|
||||
pkgver, buf, strerror(errno));
|
||||
free(buf);
|
||||
goto out;
|
||||
}
|
||||
free(buf);
|
||||
out:
|
||||
if (pkgfilesd != NULL)
|
||||
free(pkgfilesd);
|
||||
if (pkgpropsd != NULL)
|
||||
free(pkgpropsd);
|
||||
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(filesd);
|
||||
|
||||
|
22
lib/plist.c
22
lib/plist.c
@@ -266,32 +266,28 @@ xbps_array_replace_dict_by_pattern(prop_array_t array,
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
|
||||
const char *pkgname,
|
||||
const char *plist)
|
||||
xbps_pkgd_from_metadir(struct xbps_handle *xhp, const char *name)
|
||||
{
|
||||
prop_dictionary_t pkgd, plistd = NULL;
|
||||
const char *savedpkgname;
|
||||
char *plistf;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(plist != NULL);
|
||||
assert(name != NULL);
|
||||
|
||||
savedpkgname = pkgname;
|
||||
plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
|
||||
savedpkgname, plist);
|
||||
savedpkgname = name;
|
||||
plistf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, name);
|
||||
|
||||
if (access(plistf, R_OK) == -1) {
|
||||
pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false);
|
||||
pkgd = xbps_find_virtualpkg_dict_installed(xhp, name, false);
|
||||
if (pkgd == NULL)
|
||||
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
|
||||
pkgd = xbps_find_pkg_dict_installed(xhp, name, false);
|
||||
|
||||
if (pkgd != NULL) {
|
||||
free(plistf);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgname", &savedpkgname);
|
||||
plistf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
xhp->metadir, savedpkgname, plist);
|
||||
plistf = xbps_xasprintf("%s/.%s.plist",
|
||||
xhp->metadir, savedpkgname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +295,7 @@ xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
|
||||
free(plistf);
|
||||
if (plistd == NULL) {
|
||||
xbps_dbg_printf(xhp, "cannot read from metadata %s for %s: %s\n",
|
||||
plist, savedpkgname, strerror(errno));
|
||||
plistf, savedpkgname, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -69,15 +69,15 @@ xbps_rpool_init(struct xbps_handle *xhp)
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
array = prop_array_internalize_from_zfile(plist);
|
||||
free(plist);
|
||||
if (array == NULL) {
|
||||
xbps_dbg_printf(xhp,
|
||||
"[rpool] `%s' cannot be internalized:"
|
||||
" %s\n", repouri, strerror(errno));
|
||||
if (access(plist, R_OK) == -1) {
|
||||
xbps_dbg_printf(xhp, "[rpool] `%s' cannot be "
|
||||
"internalized: %s\n", repouri, strerror(errno));
|
||||
nmissing++;
|
||||
continue;
|
||||
}
|
||||
array = prop_array_internalize_from_zfile(plist);
|
||||
free(plist);
|
||||
assert(array);
|
||||
/*
|
||||
* Register repository into the array.
|
||||
*/
|
||||
|
@@ -84,7 +84,7 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgname, version,
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver, filen,
|
||||
"Verifying `%s' package integrity...", filen, repoloc);
|
||||
rv = xbps_file_hash_check(binfile, sha256);
|
||||
if (rv != 0) {
|
||||
@@ -110,6 +110,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
const char *pkgname, *version, *fetchstr;
|
||||
char *binfile;
|
||||
int rv = 0;
|
||||
bool state_dload = false;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
|
||||
@@ -150,6 +151,11 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state_dload == false) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD,
|
||||
0, NULL, NULL, NULL);
|
||||
state_dload = true;
|
||||
}
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD,
|
||||
0, pkgname, version,
|
||||
"Downloading binary package `%s' (from `%s')...",
|
||||
@@ -207,7 +213,6 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
/*
|
||||
* Download binary packages (if they come from a remote repository).
|
||||
*/
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
|
||||
if ((rv = download_binpkgs(xhp, iter)) != 0)
|
||||
goto out;
|
||||
/*
|
||||
|
@@ -97,9 +97,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
|
||||
*/
|
||||
if ((strcmp(tract, "remove") == 0) ||
|
||||
(strcmp(tract, "update") == 0)) {
|
||||
pkg_metad =
|
||||
xbps_dictionary_from_metadata_plist(xhp,
|
||||
pkgname, XBPS_PKGPROPS);
|
||||
pkg_metad = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
if (pkg_metad == NULL)
|
||||
continue;
|
||||
prop_dictionary_get_uint64(pkg_metad,
|
||||
|
@@ -41,7 +41,7 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
|
||||
char *dirc, *buf, *dname;
|
||||
char *buf;
|
||||
bool instd_auto, sr;
|
||||
size_t idx;
|
||||
|
||||
@@ -160,35 +160,21 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
"automatic-install", instd_auto);
|
||||
prop_dictionary_set_bool(instd,
|
||||
"softreplace", true);
|
||||
buf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, curpkgname,
|
||||
XBPS_PKGFILES);
|
||||
buf = xbps_xasprintf("%s/.%s.plist",
|
||||
xhp->metadir, curpkgname);
|
||||
filesd = prop_dictionary_internalize_from_zfile(buf);
|
||||
free(buf);
|
||||
assert(filesd != NULL);
|
||||
buf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, pkgname,
|
||||
XBPS_PKGFILES);
|
||||
dirc = strdup(buf);
|
||||
assert(dirc != NULL);
|
||||
dname = dirname(dirc);
|
||||
if (xbps_mkpath(dname, 0755) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
free(buf);
|
||||
prop_object_iterator_release(iter);
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
buf = xbps_xasprintf("%s/.%s.plist",
|
||||
xhp->metadir, pkgname);
|
||||
if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
|
||||
free(buf);
|
||||
free(dirc);
|
||||
prop_object_release(filesd);
|
||||
prop_object_iterator_release(iter);
|
||||
return errno;
|
||||
}
|
||||
prop_object_release(filesd);
|
||||
free(buf);
|
||||
free(dirc);
|
||||
}
|
||||
/*
|
||||
* Add package dictionary into the transaction and mark
|
||||
|
Reference in New Issue
Block a user