Moved install transaction code to libxbps, see NEWS file.
This commit is contained in:
@@ -40,7 +40,7 @@ endif
|
||||
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_purge.o package_replaces.o
|
||||
OBJS += package_purge.o package_replaces.o transaction_commit.o
|
||||
OBJS += transaction_dictionary.o transaction_sortdeps.o
|
||||
OBJS += download.o fexec.o humanize_number.o plist.o
|
||||
OBJS += plist_archive_entry.o plist_find.o plist_match.o plist_remove.o
|
||||
|
||||
@@ -90,7 +90,7 @@ xbps_fetch_file(const char *uri,
|
||||
bool refetch,
|
||||
const char *flags)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
struct stat st;
|
||||
struct url *url = NULL;
|
||||
struct url_stat url_st;
|
||||
@@ -263,15 +263,15 @@ xbps_fetch_file(const char *uri,
|
||||
* and let the user know that the transfer is going to start
|
||||
* immediately.
|
||||
*/
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL && xhp->xfpd != NULL) {
|
||||
xhp->xfpd->file_name = filename;
|
||||
xhp->xfpd->file_size = url_st.size;
|
||||
xhp->xfpd->file_offset = url->offset;
|
||||
xhp->xfpd->file_dloaded = -1;
|
||||
xhp->xfpd->cb_start = true;
|
||||
xhp->xfpd->cb_update = false;
|
||||
xhp->xfpd->cb_end = false;
|
||||
xhp->xbps_fetch_cb(xhp->xfpd);
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL && xhp->xfcd != NULL) {
|
||||
xhp->xfcd->file_name = filename;
|
||||
xhp->xfcd->file_size = url_st.size;
|
||||
xhp->xfcd->file_offset = url->offset;
|
||||
xhp->xfcd->file_dloaded = -1;
|
||||
xhp->xfcd->cb_start = true;
|
||||
xhp->xfcd->cb_update = false;
|
||||
xhp->xfcd->cb_end = false;
|
||||
xhp->xbps_fetch_cb(xhp->xfcd);
|
||||
}
|
||||
/*
|
||||
* Start fetching requested file.
|
||||
@@ -289,11 +289,11 @@ xbps_fetch_file(const char *uri,
|
||||
* we are sucking more bytes from it.
|
||||
*/
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL &&
|
||||
xhp->xfpd != NULL) {
|
||||
xhp->xfpd->file_dloaded = bytes_dload;
|
||||
xhp->xfpd->cb_start = false;
|
||||
xhp->xfpd->cb_update = true;
|
||||
xhp->xbps_fetch_cb(xhp->xfpd);
|
||||
xhp->xfcd != NULL) {
|
||||
xhp->xfcd->file_dloaded = bytes_dload;
|
||||
xhp->xfcd->cb_start = false;
|
||||
xhp->xfcd->cb_update = true;
|
||||
xhp->xbps_fetch_cb(xhp->xfcd);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -301,10 +301,10 @@ xbps_fetch_file(const char *uri,
|
||||
* Let the fetch progress callback know that the file
|
||||
* has been fetched.
|
||||
*/
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL && xhp->xfpd != NULL) {
|
||||
xhp->xfpd->cb_update = false;
|
||||
xhp->xfpd->cb_end = true;
|
||||
xhp->xbps_fetch_cb(xhp->xfpd);
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL && xhp->xfcd != NULL) {
|
||||
xhp->xfcd->cb_update = false;
|
||||
xhp->xfcd->cb_end = true;
|
||||
xhp->xbps_fetch_cb(xhp->xfcd);
|
||||
}
|
||||
if (bytes_read == -1) {
|
||||
xbps_error_printf("IO error while fetching %s: %s\n", filename,
|
||||
|
||||
@@ -52,7 +52,7 @@ xbps_init(struct xbps_handle *xh)
|
||||
assert(xh != NULL);
|
||||
|
||||
xhp = xh;
|
||||
debug = xhp->with_debug;
|
||||
debug = xhp->debug;
|
||||
|
||||
/* If conffile not set, defaults to XBPS_CONF_PATH */
|
||||
if (xhp->conffile == NULL)
|
||||
@@ -67,7 +67,7 @@ xbps_init(struct xbps_handle *xh)
|
||||
if (errno != ENOENT) {
|
||||
xbps_dbg_printf("%s: cannot internalize conf "
|
||||
"dictionary: %s\n", strerror(errno));
|
||||
xbps_end();
|
||||
xbps_end(xh);
|
||||
return errno;
|
||||
}
|
||||
xbps_dbg_printf("%s: conf_dictionary not internalized.\n",
|
||||
@@ -101,9 +101,22 @@ xbps_init(struct xbps_handle *xh)
|
||||
}
|
||||
}
|
||||
if (xhp->cachedir == NULL) {
|
||||
if (conf_cachedir != NULL)
|
||||
xhp->cachedir = conf_cachedir;
|
||||
else {
|
||||
if (conf_cachedir != NULL) {
|
||||
if (conf_cachedir[0] == '/') {
|
||||
/* full path */
|
||||
xhp->cachedir = conf_cachedir;
|
||||
} else {
|
||||
/* relative to rootdir */
|
||||
xhp->pstring_cachedir =
|
||||
prop_string_create_cstring(xhp->rootdir);
|
||||
prop_string_append_cstring(
|
||||
xhp->pstring_cachedir, "/");
|
||||
prop_string_append_cstring(
|
||||
xhp->pstring_cachedir, conf_cachedir);
|
||||
xhp->cachedir = prop_string_cstring_nocopy(
|
||||
xhp->pstring_cachedir);
|
||||
}
|
||||
} else {
|
||||
/* If cachedir not set, defaults to XBPS_CACHE_PATH */
|
||||
xhp->cachedir = XBPS_CACHE_PATH;
|
||||
}
|
||||
@@ -130,7 +143,7 @@ xbps_init(struct xbps_handle *xh)
|
||||
if (rv != ENOENT) {
|
||||
xbps_dbg_printf("%s: couldn't initialize "
|
||||
"regpkgdb: %s\n", strerror(rv));
|
||||
xbps_end();
|
||||
xbps_end(xh);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -139,27 +152,68 @@ xbps_init(struct xbps_handle *xh)
|
||||
}
|
||||
|
||||
void
|
||||
xbps_end(void)
|
||||
xbps_end(struct xbps_handle *xh)
|
||||
{
|
||||
xbps_regpkgdb_dictionary_release();
|
||||
xbps_repository_pool_release();
|
||||
xbps_fetch_unset_cache_connection();
|
||||
if (xhp == NULL)
|
||||
if (xh == NULL)
|
||||
return;
|
||||
|
||||
if (prop_object_type(xhp->conf_dictionary) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(xhp->conf_dictionary);
|
||||
if (prop_object_type(xh->conf_dictionary) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(xh->conf_dictionary);
|
||||
if (prop_object_type(xh->pstring_cachedir) == PROP_TYPE_STRING)
|
||||
prop_object_release(xh->pstring_cachedir);
|
||||
|
||||
if (xh->xfcd != NULL)
|
||||
free(xh->xfcd);
|
||||
if (xh->xucd != NULL)
|
||||
free(xh->xucd);
|
||||
if (xh->xtcd != NULL)
|
||||
free(xh->xtcd);
|
||||
|
||||
free(xh);
|
||||
xh = NULL;
|
||||
xhp = NULL;
|
||||
}
|
||||
|
||||
const struct xbps_handle *
|
||||
struct xbps_handle *
|
||||
xbps_handle_get(void)
|
||||
{
|
||||
assert(xhp != NULL);
|
||||
return xhp;
|
||||
}
|
||||
|
||||
struct xbps_handle *
|
||||
xbps_handle_alloc(void)
|
||||
{
|
||||
struct xbps_handle *xh;
|
||||
|
||||
xh = calloc(1, sizeof(struct xbps_handle));
|
||||
if (xh == NULL)
|
||||
return NULL;
|
||||
xh->xtcd = calloc(1, sizeof(struct xbps_transaction_cb_data));
|
||||
if (xh->xtcd == NULL) {
|
||||
free(xh);
|
||||
return NULL;
|
||||
}
|
||||
xh->xucd = calloc(1, sizeof(struct xbps_unpack_cb_data));
|
||||
if (xh->xucd == NULL) {
|
||||
free(xh->xtcd);
|
||||
free(xh);
|
||||
return NULL;
|
||||
}
|
||||
xh->xfcd = calloc(1, sizeof(struct xbps_fetch_cb_data));
|
||||
if (xh->xfcd == NULL) {
|
||||
free(xh->xucd);
|
||||
free(xh->xtcd);
|
||||
free(xh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return xh;
|
||||
}
|
||||
|
||||
static void
|
||||
common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
int
|
||||
xbps_configure_packages(void)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname, *version;
|
||||
@@ -79,13 +79,12 @@ xbps_configure_pkg(const char *pkgname,
|
||||
bool check_state,
|
||||
bool update)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t pkgd;
|
||||
const char *lver;
|
||||
char *buf, *pkgver;
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
bool reconfigure = false;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
xhp = xbps_handle_get();
|
||||
@@ -98,8 +97,6 @@ xbps_configure_pkg(const char *pkgname,
|
||||
if (state == XBPS_PKG_STATE_INSTALLED) {
|
||||
if ((xhp->flags & XBPS_FLAG_FORCE) == 0)
|
||||
return 0;
|
||||
|
||||
reconfigure = true;
|
||||
} else if (state != XBPS_PKG_STATE_UNPACKED)
|
||||
return EINVAL;
|
||||
|
||||
@@ -110,18 +107,31 @@ xbps_configure_pkg(const char *pkgname,
|
||||
lver = version;
|
||||
}
|
||||
|
||||
xbps_printf("%sonfiguring package `%s-%s' ...\n",
|
||||
reconfigure ? "Rec" : "C", pkgname, lver);
|
||||
pkgver = xbps_xasprintf("%s-%s", pkgname, lver);
|
||||
if (pkgver == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
if (xhp->xbps_transaction_cb) {
|
||||
xhp->xtcd->desc = NULL;
|
||||
xhp->xtcd->binpkg_fname = NULL;
|
||||
xhp->xtcd->binpkg_repourl = NULL;
|
||||
xhp->xtcd->state = XBPS_TRANS_STATE_CONFIGURE;
|
||||
xhp->xtcd->pkgver = pkgver;
|
||||
xhp->xbps_transaction_cb(xhp->xtcd);
|
||||
}
|
||||
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
||||
XBPS_META_PATH, pkgname);
|
||||
if (buf == NULL)
|
||||
if (buf == NULL) {
|
||||
free(pkgver);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
xbps_dbg_printf("%s: [configure] chdir to '%s' returned %s\n",
|
||||
pkgname, xhp->rootdir, strerror(errno));
|
||||
free(buf);
|
||||
free(pkgver);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
@@ -129,6 +139,7 @@ xbps_configure_pkg(const char *pkgname,
|
||||
if (xbps_file_exec(buf, "post",
|
||||
pkgname, lver, update ? "yes" : "no", NULL) != 0) {
|
||||
free(buf);
|
||||
free(pkgver);
|
||||
xbps_error_printf("%s: post install script error: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
return errno;
|
||||
@@ -136,14 +147,11 @@ xbps_configure_pkg(const char *pkgname,
|
||||
} else {
|
||||
if (errno != ENOENT) {
|
||||
free(buf);
|
||||
free(pkgver);
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
pkgver = xbps_xasprintf("%s-%s", pkgname, lver);
|
||||
if (pkgver == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
rv = xbps_set_pkg_state_installed(pkgname, lver, pkgver,
|
||||
XBPS_PKG_STATE_INSTALLED);
|
||||
free(pkgver);
|
||||
|
||||
@@ -147,6 +147,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(pkgdepname);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
@@ -161,7 +162,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
|
||||
prop_array_t
|
||||
xbps_find_pkg_orphans(prop_array_t orphans_user)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_array_t array = NULL;
|
||||
struct orphan_data od;
|
||||
int rv = 0;
|
||||
@@ -186,5 +187,6 @@ xbps_find_pkg_orphans(prop_array_t orphans_user)
|
||||
return NULL;
|
||||
}
|
||||
array = prop_array_copy(od.array);
|
||||
prop_object_release(od.array);
|
||||
return array;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ remove_pkg_metadata(const char *pkgname, const char *rootdir)
|
||||
int
|
||||
xbps_purge_packages(void)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname;
|
||||
@@ -118,7 +118,7 @@ xbps_purge_packages(void)
|
||||
int
|
||||
xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t dict, pkgd;
|
||||
const char *version;
|
||||
char *buf;
|
||||
|
||||
@@ -42,13 +42,13 @@
|
||||
int
|
||||
xbps_register_pkg(prop_dictionary_t pkgrd)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t dict, pkgd;
|
||||
prop_array_t array, provides = NULL;
|
||||
const char *pkgname, *version, *desc, *pkgver;
|
||||
char *plist;
|
||||
int rv = 0;
|
||||
bool autoinst;
|
||||
bool autoinst = false;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
@@ -149,7 +149,7 @@ out:
|
||||
int
|
||||
xbps_unregister_pkg(const char *pkgname)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
char *plist;
|
||||
int rv = 0;
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
int
|
||||
xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_array_t array;
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
@@ -172,7 +172,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
|
||||
int
|
||||
xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t dict;
|
||||
const char *pkgver;
|
||||
char *buf;
|
||||
|
||||
@@ -102,7 +102,7 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
|
||||
int HIDDEN
|
||||
xbps_requiredby_pkg_remove(const char *pkgname)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t dict;
|
||||
char *plist;
|
||||
int rv = 0;
|
||||
|
||||
@@ -164,7 +164,7 @@ xbps_set_pkg_state_installed(const char *pkgname,
|
||||
const char *pkgver,
|
||||
pkg_state_t state)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t dict = NULL, pkgd;
|
||||
prop_array_t array;
|
||||
char *plist;
|
||||
|
||||
@@ -152,8 +152,8 @@ remove_metafile(const char *file, const char *pkgname, const char *version)
|
||||
*/
|
||||
#define RUN_PROGRESS_CB() \
|
||||
do { \
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL && xhp->xupd != NULL) \
|
||||
(*xhp->xbps_unpack_cb)(xhp->xupd); \
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL && xhp->xucd != NULL) \
|
||||
(*xhp->xbps_unpack_cb)(xhp->xucd); \
|
||||
} while (0)
|
||||
|
||||
static int
|
||||
@@ -161,7 +161,7 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
struct archive *ar,
|
||||
const char *pkgname,
|
||||
const char *version,
|
||||
const struct xbps_handle *xhp)
|
||||
struct xbps_handle *xhp)
|
||||
{
|
||||
prop_dictionary_t propsd = NULL, filesd = NULL, old_filesd = NULL;
|
||||
prop_array_t array;
|
||||
@@ -211,11 +211,11 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
entry_pname = archive_entry_pathname(entry);
|
||||
set_extract_flags(&flags, update);
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL &&
|
||||
xhp->xupd != NULL) {
|
||||
xhp->xupd->entry = entry_pname;
|
||||
xhp->xupd->entry_size = archive_entry_size(entry);
|
||||
xhp->xupd->entry_is_metadata = false;
|
||||
xhp->xupd->entry_is_conf = false;
|
||||
xhp->xucd != NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (strcmp("./INSTALL", entry_pname) == 0) {
|
||||
@@ -245,9 +245,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
}
|
||||
nmetadata++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
if (xhp->xucd != NULL) {
|
||||
xhp->xucd->entry_is_metadata = true;
|
||||
xhp->xucd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@@ -259,9 +259,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
|
||||
nmetadata++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
if (xhp->xucd != NULL) {
|
||||
xhp->xucd->entry_is_metadata = true;
|
||||
xhp->xucd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@@ -278,9 +278,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
}
|
||||
nmetadata++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
if (xhp->xucd != NULL) {
|
||||
xhp->xucd->entry_is_metadata = true;
|
||||
xhp->xucd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@@ -298,9 +298,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
}
|
||||
nmetadata++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
if (xhp->xucd != NULL) {
|
||||
xhp->xucd->entry_is_metadata = true;
|
||||
xhp->xucd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@@ -329,16 +329,16 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
* Compute total entries in progress data, if set.
|
||||
* total_entries = metadata + files + conf_files + links.
|
||||
*/
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_total_count = nmetadata;
|
||||
if (xhp->xucd != NULL) {
|
||||
xhp->xucd->entry_total_count = nmetadata;
|
||||
array = prop_dictionary_get(filesd, "files");
|
||||
xhp->xupd->entry_total_count +=
|
||||
xhp->xucd->entry_total_count +=
|
||||
(ssize_t)prop_array_count(array);
|
||||
array = prop_dictionary_get(filesd, "conf_files");
|
||||
xhp->xupd->entry_total_count +=
|
||||
xhp->xucd->entry_total_count +=
|
||||
(ssize_t)prop_array_count(array);
|
||||
array = prop_dictionary_get(filesd, "links");
|
||||
xhp->xupd->entry_total_count +=
|
||||
xhp->xucd->entry_total_count +=
|
||||
(ssize_t)prop_array_count(array);
|
||||
}
|
||||
|
||||
@@ -353,8 +353,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
/* error */
|
||||
goto out;
|
||||
} else if (rv == 1) {
|
||||
if (xhp->xupd != NULL)
|
||||
xhp->xupd->entry_is_conf = true;
|
||||
if (xhp->xucd != NULL)
|
||||
xhp->xucd->entry_is_conf = true;
|
||||
|
||||
rv = xbps_entry_install_conf_file(filesd,
|
||||
entry, entry_pname, pkgname, version);
|
||||
@@ -396,8 +396,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (xhp->xupd != NULL)
|
||||
xhp->xupd->entry_extract_count++;
|
||||
if (xhp->xucd != NULL)
|
||||
xhp->xucd->entry_extract_count++;
|
||||
|
||||
RUN_PROGRESS_CB();
|
||||
}
|
||||
@@ -462,7 +462,7 @@ out:
|
||||
int
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
struct archive *ar;
|
||||
const char *pkgname, *version, *repoloc, *pkgver;
|
||||
char *bpkg;
|
||||
@@ -503,9 +503,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
||||
* Set extract progress callback if specified.
|
||||
*/
|
||||
xhp = xbps_handle_get();
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL && xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_extract_count = 0;
|
||||
xhp->xupd->entry_total_count = 0;
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL && xhp->xucd != NULL) {
|
||||
xhp->xucd->entry_extract_count = 0;
|
||||
xhp->xucd->entry_total_count = 0;
|
||||
}
|
||||
/*
|
||||
* Extract archive files.
|
||||
|
||||
@@ -186,7 +186,7 @@ prop_dictionary_t
|
||||
xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
const char *plist)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t pkgd, plistd = NULL;
|
||||
const char *rpkgname;
|
||||
char *plistf;
|
||||
|
||||
@@ -322,7 +322,7 @@ xbps_find_pkg_dict_from_plist_by_pattern(const char *plist,
|
||||
static prop_dictionary_t
|
||||
find_pkgd_installed(const char *str, bool bypattern, bool virtual)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t pkgd, rpkgd = NULL;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp)
|
||||
void HIDDEN
|
||||
xbps_regpkgdb_dictionary_release(void)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
|
||||
if (!regpkgdb_initialized)
|
||||
return;
|
||||
|
||||
@@ -176,7 +176,7 @@ out:
|
||||
int
|
||||
xbps_repository_update_packages(void)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname;
|
||||
|
||||
@@ -56,7 +56,7 @@ static bool repolist_initialized;
|
||||
int HIDDEN
|
||||
xbps_repository_pool_init(void)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
prop_array_t array;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter = NULL;
|
||||
@@ -258,7 +258,7 @@ xbps_repository_pool_foreach(
|
||||
xbps_dbg_printf("%s: couldn't initialize "
|
||||
"repository pool: %s\n", __func__, strerror(rv));
|
||||
}
|
||||
xbps_end();
|
||||
xbps_end(xbps_handle_get());
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ xbps_get_remote_repo_string(const char *uri)
|
||||
int
|
||||
xbps_repository_sync_pkg_index(const char *uri)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
struct url *url = NULL;
|
||||
struct utsname un;
|
||||
struct stat st;
|
||||
|
||||
360
lib/transaction_commit.c
Normal file
360
lib/transaction_commit.c
Normal file
@@ -0,0 +1,360 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2011 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 <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
#define RUN_TRANS_CB(s, d, p, bf, burl) \
|
||||
do { \
|
||||
if (xhp->xbps_transaction_cb != NULL) { \
|
||||
xhp->xtcd->state = s; \
|
||||
xhp->xtcd->desc = d; \
|
||||
xhp->xtcd->pkgver = p; \
|
||||
xhp->xtcd->binpkg_fname = bf; \
|
||||
xhp->xtcd->binpkg_repourl = burl; \
|
||||
(*xhp->xbps_transaction_cb)(xhp->xtcd); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RUN_TRANS_ERR_CB(s, p, r) \
|
||||
do { \
|
||||
if (xhp->xbps_transaction_err_cb != NULL) { \
|
||||
xhp->xtcd->state = s; \
|
||||
xhp->xtcd->pkgver = p; \
|
||||
xhp->xtcd->err = r; \
|
||||
(*xhp->xbps_transaction_err_cb)(xhp->xtcd); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int
|
||||
check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *repoloc, *filename, *sha256, *trans;
|
||||
char *binfile;
|
||||
int rv = 0;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
|
||||
if ((strcmp(trans, "remove") == 0) ||
|
||||
(strcmp(trans, "configure") == 0))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
assert(repoloc != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
assert(pkgver != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
assert(filename != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"filename-sha256", &sha256);
|
||||
assert(sha256 != NULL);
|
||||
|
||||
binfile = xbps_path_from_repository_uri(obj, repoloc);
|
||||
if (binfile == NULL) {
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_VERIFY,
|
||||
NULL, pkgver, filename, repoloc);
|
||||
rv = xbps_file_hash_check(binfile, sha256);
|
||||
if (rv != 0) {
|
||||
free(binfile);
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_VERIFY, pkgver, rv);
|
||||
break;
|
||||
}
|
||||
free(binfile);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *repoloc, *filename, *trans;
|
||||
char *binfile;
|
||||
int rv = 0;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
|
||||
if ((strcmp(trans, "remove") == 0) ||
|
||||
(strcmp(trans, "configure") == 0))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
assert(repoloc != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
assert(pkgver != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
assert(filename != NULL);
|
||||
|
||||
binfile = xbps_path_from_repository_uri(obj, repoloc);
|
||||
if (binfile == NULL) {
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* If downloaded package is in cachedir continue.
|
||||
*/
|
||||
if (access(binfile, R_OK) == 0) {
|
||||
free(binfile);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Create cachedir.
|
||||
*/
|
||||
if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
|
||||
xbps_error_printf("xbps-bin: cannot mkdir cachedir "
|
||||
"`%s': %s.\n", xhp->cachedir, strerror(errno));
|
||||
free(binfile);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_DOWNLOAD,
|
||||
NULL, pkgver, filename, repoloc);
|
||||
/*
|
||||
* Fetch binary package.
|
||||
*/
|
||||
rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL);
|
||||
if (rv == -1) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_DOWNLOAD, pkgver, errno);
|
||||
free(binfile);
|
||||
break;
|
||||
}
|
||||
rv = 0;
|
||||
free(binfile);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_transaction_commit(prop_dictionary_t transd)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname, *version, *pkgver, *filen, *tract;
|
||||
int rv = 0;
|
||||
bool update, preserve;
|
||||
pkg_state_t state;
|
||||
|
||||
assert(transd != NULL);
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
iter = xbps_array_iter_from_dict(transd, "packages");
|
||||
if (iter == NULL)
|
||||
return EINVAL;
|
||||
/*
|
||||
* Download binary packages (if they come from a remote repository).
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_DOWNLOAD,
|
||||
"[*] Downloading binary packages", NULL, NULL, NULL);
|
||||
if ((rv = download_binpkgs(xhp, iter)) != 0)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Check SHA256 hashes for binary packages in transaction.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_VERIFY,
|
||||
"[*] Verifying binary package integrity", NULL, NULL, NULL);
|
||||
if ((rv = check_binpkgs_hash(xhp, iter)) != 0)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Remove packages to be replaced.
|
||||
*/
|
||||
if (prop_dictionary_get(transd, "total-remove-pkgs")) {
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_REPLACE,
|
||||
"[*] Removing packages to be replaced", NULL, NULL, NULL);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction",
|
||||
&tract);
|
||||
if (strcmp(tract, "remove"))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
|
||||
&pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version",
|
||||
&version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver",
|
||||
&pkgver);
|
||||
update = false;
|
||||
prop_dictionary_get_bool(obj, "remove-and-update",
|
||||
&update);
|
||||
|
||||
/* Remove and purge packages that shall be replaced */
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_REMOVE,
|
||||
NULL, pkgver, NULL, NULL);
|
||||
rv = xbps_remove_pkg(pkgname, version, update);
|
||||
if (rv != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_REMOVE,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
if (!update)
|
||||
continue;
|
||||
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_PURGE,
|
||||
NULL, pkgver, NULL, NULL);
|
||||
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_PURGE,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
}
|
||||
/*
|
||||
* Configure pending packages.
|
||||
*/
|
||||
if (prop_dictionary_get(transd, "total-configure-pkgs")) {
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_CONFIGURE,
|
||||
"[*] Reconfigure unpacked packages", NULL, NULL, NULL);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction",
|
||||
&tract);
|
||||
if (strcmp(tract, "configure"))
|
||||
continue;
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
|
||||
&pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version",
|
||||
&version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver",
|
||||
&pkgver);
|
||||
|
||||
rv = xbps_configure_pkg(pkgname, version, false, false);
|
||||
if (rv != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_CONFIGURE,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
}
|
||||
/*
|
||||
* Install or update packages in transaction.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_INSTALL,
|
||||
"[*] Unpacking packages to be installed/updated", NULL, NULL, NULL);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
||||
/* Match only packages to be installed or updated */
|
||||
if ((strcmp(tract, "remove") == 0) ||
|
||||
(strcmp(tract, "configure") == 0))
|
||||
continue;
|
||||
|
||||
preserve = false;
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
|
||||
prop_dictionary_get_bool(obj, "preserve", &preserve);
|
||||
/*
|
||||
* If dependency is already unpacked skip this phase.
|
||||
*/
|
||||
state = 0;
|
||||
if (xbps_pkg_state_dictionary(obj, &state) != 0) {
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (state == XBPS_PKG_STATE_UNPACKED)
|
||||
continue;
|
||||
|
||||
if (strcmp(tract, "update") == 0) {
|
||||
/* Update a package, execute pre-remove action if found */
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_UPDATE,
|
||||
NULL, pkgver, filen, NULL);
|
||||
if ((rv = xbps_remove_pkg(pkgname, version, true)) != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_UPDATE,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Unpack binary package.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_UNPACK, NULL, pkgver, filen, NULL);
|
||||
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_UNPACK, pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Register binary package.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_REGISTER,
|
||||
NULL, pkgver, filen, NULL);
|
||||
if ((rv = xbps_register_pkg(obj)) != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_REGISTER, pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
/*
|
||||
* Configure all unpacked packages.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_CONFIGURE,
|
||||
"[*] Configuring packages installed/updated", NULL, NULL, NULL);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
||||
if ((strcmp(tract, "remove") == 0) ||
|
||||
(strcmp(tract, "configure") == 0))
|
||||
continue;
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
update = false;
|
||||
if (strcmp(tract, "update") == 0)
|
||||
update = true;
|
||||
|
||||
rv = xbps_configure_pkg(pkgname, version, false, update);
|
||||
if (rv != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_CONFIGURE, pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ xbps_pkgpattern_version(const char *pkg)
|
||||
static char *
|
||||
get_pkg_index_remote_plist(const char *uri)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
char *uri_fixed, *repodir;
|
||||
|
||||
assert(uri != NULL);
|
||||
@@ -243,7 +243,7 @@ xbps_pkg_index_plist(const char *uri)
|
||||
char *
|
||||
xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
struct xbps_handle *xhp;
|
||||
const char *filen, *arch;
|
||||
char *lbinpkg = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user