2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-04 22:11:36 +05:30
|
|
|
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
2011-01-19 05:01:22 +05:30
|
|
|
* @file lib/package_configure.c
|
2010-01-21 07:40:19 +05:30
|
|
|
* @brief Package configuration routines
|
|
|
|
* @defgroup configure Package configuration functions
|
|
|
|
*
|
2010-01-23 07:07:19 +05:30
|
|
|
* Configure a package or all packages. Only packages in XBPS_PKG_STATE_UNPACKED
|
2010-01-21 07:40:19 +05:30
|
|
|
* state will be processed (unless overriden). Package configuration steps:
|
2010-01-23 04:29:55 +05:30
|
|
|
* - Its <b>post-install</b> target in the INSTALL script will be executed.
|
2010-01-23 07:07:19 +05:30
|
|
|
* - Its state will be changed to XBPS_PKG_STATE_INSTALLED if previous step
|
2010-01-23 04:29:55 +05:30
|
|
|
* ran successful.
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* @note
|
2011-11-24 16:20:53 +05:30
|
|
|
* If the \a XBPS_FLAG_FORCE_CONFIGURE is set through xbps_init() in the flags
|
2011-02-21 22:12:47 +05:30
|
|
|
* member, the package (or packages) will be reconfigured even if its
|
|
|
|
* state is XBPS_PKG_STATE_INSTALLED.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
2011-12-23 12:46:25 +05:30
|
|
|
int
|
2012-01-04 22:11:36 +05:30
|
|
|
xbps_configure_packages(bool flush)
|
2011-12-23 12:46:25 +05:30
|
|
|
{
|
2012-02-29 01:46:41 +05:30
|
|
|
struct xbps_handle *xhp = xbps_handle_get();
|
|
|
|
prop_object_t obj;
|
|
|
|
const char *pkgname, *version;
|
|
|
|
size_t i;
|
2012-01-04 22:11:36 +05:30
|
|
|
int rv;
|
|
|
|
|
2012-02-29 01:46:41 +05:30
|
|
|
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
for (i = 0; i < prop_array_count(xhp->pkgdb); i++) {
|
|
|
|
obj = prop_array_get(xhp->pkgdb, i);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
rv = xbps_configure_pkg(pkgname, version, true, false, false);
|
|
|
|
if (rv != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flush)
|
2012-01-22 14:30:46 +05:30
|
|
|
rv = xbps_pkgdb_update(true);
|
2012-01-04 22:11:36 +05:30
|
|
|
|
|
|
|
return rv;
|
2009-08-21 15:01:26 +05:30
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_configure_pkg(const char *pkgname,
|
|
|
|
const char *version,
|
|
|
|
bool check_state,
|
2012-01-04 22:11:36 +05:30
|
|
|
bool update,
|
|
|
|
bool flush)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-07-27 20:43:54 +05:30
|
|
|
struct xbps_handle *xhp;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_dictionary_t pkgd;
|
2011-02-21 22:12:47 +05:30
|
|
|
const char *lver;
|
2011-02-22 15:39:39 +05:30
|
|
|
char *buf, *pkgver;
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
pkg_state_t state = 0;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
2011-02-21 22:12:47 +05:30
|
|
|
xhp = xbps_handle_get();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-08-21 15:01:26 +05:30
|
|
|
if (check_state) {
|
2011-06-01 13:07:32 +05:30
|
|
|
rv = xbps_pkg_state_installed(pkgname, &state);
|
2012-03-31 13:38:52 +05:30
|
|
|
xbps_dbg_printf("%s: state %d rv %d\n", pkgname, state, rv);
|
2011-10-20 19:43:16 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
/*
|
2011-12-24 05:35:26 +05:30
|
|
|
* package not installed or has been removed.
|
2011-10-20 19:43:16 +05:30
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
} else if (rv != 0) {
|
|
|
|
xbps_dbg_printf("%s: [configure] failed to get "
|
|
|
|
"pkg state: %s\n", pkgname, strerror(rv));
|
2010-11-19 18:10:13 +05:30
|
|
|
return EINVAL;
|
2011-10-20 19:43:16 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-08-21 15:01:26 +05:30
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED) {
|
2011-11-24 16:20:53 +05:30
|
|
|
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0)
|
2009-08-21 15:01:26 +05:30
|
|
|
return 0;
|
|
|
|
} else if (state != XBPS_PKG_STATE_UNPACKED)
|
|
|
|
return EINVAL;
|
2009-08-25 09:33:02 +05:30
|
|
|
|
2012-01-20 15:40:52 +05:30
|
|
|
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "version", &lver);
|
2009-08-25 09:33:02 +05:30
|
|
|
prop_object_release(pkgd);
|
|
|
|
} else {
|
|
|
|
lver = version;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-07-27 20:43:54 +05:30
|
|
|
pkgver = xbps_xasprintf("%s-%s", pkgname, lver);
|
|
|
|
if (pkgver == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2011-11-25 14:14:49 +05:30
|
|
|
xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, lver, NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-12-15 19:16:59 +05:30
|
|
|
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
|
2009-08-17 22:37:20 +05:30
|
|
|
XBPS_META_PATH, pkgname);
|
2011-07-27 20:43:54 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
free(pkgver);
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
2011-07-27 20:43:54 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-12-15 15:49:20 +05:30
|
|
|
if (chdir(xhp->rootdir) == -1) {
|
2011-11-24 15:53:08 +05:30
|
|
|
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
|
|
|
|
pkgname, lver,
|
|
|
|
"%s: [configure] failed to chdir to rootdir `%s': %s",
|
2011-12-15 15:49:20 +05:30
|
|
|
pkgver, xhp->rootdir, strerror(errno));
|
2009-11-26 07:52:50 +05:30
|
|
|
free(buf);
|
2011-07-27 20:43:54 +05:30
|
|
|
free(pkgver);
|
2010-11-19 18:10:13 +05:30
|
|
|
return EINVAL;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if (access(buf, X_OK) == 0) {
|
|
|
|
if (xbps_file_exec(buf, "post",
|
2011-12-15 16:54:59 +05:30
|
|
|
pkgname, lver, update ? "yes" : "no",
|
|
|
|
xhp->conffile, NULL) != 0) {
|
2011-11-24 15:53:08 +05:30
|
|
|
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
|
|
|
|
pkgname, lver,
|
|
|
|
"%s: [configure] INSTALL script failed to execute "
|
|
|
|
"the post ACTION: %s", pkgver, strerror(errno));
|
2010-11-19 18:10:13 +05:30
|
|
|
free(buf);
|
2011-07-27 20:43:54 +05:30
|
|
|
free(pkgver);
|
2010-11-19 18:10:13 +05:30
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (errno != ENOENT) {
|
2012-03-31 13:38:52 +05:30
|
|
|
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
|
|
|
|
pkgname, lver,
|
|
|
|
"%s: [configure] INSTALL script cannot be "
|
|
|
|
"executed: %s", pkgver, strerror(errno));
|
2010-11-19 18:10:13 +05:30
|
|
|
free(buf);
|
2011-07-27 20:43:54 +05:30
|
|
|
free(pkgver);
|
2010-11-19 18:10:13 +05:30
|
|
|
return errno;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
free(buf);
|
2012-04-10 13:13:59 +05:30
|
|
|
rv = xbps_set_pkg_state_installed(pkgname, lver,
|
2011-02-22 15:39:39 +05:30
|
|
|
XBPS_PKG_STATE_INSTALLED);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv,
|
|
|
|
pkgname, lver,
|
|
|
|
"%s: [configure] failed to set state to installed: %s",
|
|
|
|
pkgver, strerror(rv));
|
2011-11-11 14:11:48 +05:30
|
|
|
}
|
2011-11-24 15:53:08 +05:30
|
|
|
free(pkgver);
|
2012-03-31 13:38:52 +05:30
|
|
|
if (flush) {
|
|
|
|
if ((rv = xbps_pkgdb_update(true)) != 0) {
|
|
|
|
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv,
|
|
|
|
pkgname, lver,
|
|
|
|
"%s: [configure] failed to update pkgdb: %s\n",
|
|
|
|
pkgver, strerror(rv));
|
|
|
|
}
|
|
|
|
}
|
2011-02-22 15:39:39 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|