2014-10-19 14:30:40 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2014-10-19 14:30:40 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
bool HIDDEN
|
2014-10-19 14:30:40 +05:30
|
|
|
xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_t pkgrd, bool autoinst)
|
2014-10-19 14:30:40 +05:30
|
|
|
{
|
2020-02-14 12:49:55 +05:30
|
|
|
xbps_dictionary_t d, pkgd;
|
2014-10-19 14:30:40 +05:30
|
|
|
xbps_array_t replaces;
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver, *pkgname, *curpkgver, *repo;
|
|
|
|
char *self_replaced;
|
2020-02-14 12:49:55 +05:30
|
|
|
int rv;
|
2014-10-19 14:30:40 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
assert(xhp);
|
|
|
|
assert(pkgs);
|
|
|
|
assert(pkgrd);
|
|
|
|
|
2020-02-14 12:49:55 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2020-02-14 12:49:55 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname)) {
|
|
|
|
return false;
|
2020-02-14 12:49:55 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
d = xbps_find_pkg_in_array(pkgs, pkgname, 0);
|
2020-02-14 12:49:55 +05:30
|
|
|
if (xbps_object_type(d) == XBPS_TYPE_DICTIONARY) {
|
|
|
|
/* compare version stored in transaction vs current */
|
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(d, "pkgver", &curpkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2020-02-14 12:49:55 +05:30
|
|
|
}
|
|
|
|
rv = xbps_cmpver(pkgver, curpkgver);
|
|
|
|
if (rv == 0 || rv == -1) {
|
|
|
|
/* same version or stored version greater than current */
|
2020-02-21 13:38:22 +05:30
|
|
|
return true;
|
2020-02-14 12:49:55 +05:30
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Current version is greater than stored,
|
|
|
|
* replace stored with current.
|
|
|
|
*/
|
|
|
|
if (!xbps_remove_pkg_from_array_by_pkgver(pkgs, curpkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2020-02-14 12:49:55 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dbg_printf(xhp, "[trans] replaced %s with %s\n", curpkgver, pkgver);
|
2020-02-14 12:49:55 +05:30
|
|
|
}
|
|
|
|
}
|
2020-02-10 04:50:13 +05:30
|
|
|
|
|
|
|
if ((pkgd = xbps_dictionary_copy_mutable(pkgrd)) == NULL)
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2020-02-10 04:50:13 +05:30
|
|
|
|
2014-10-19 14:30:40 +05:30
|
|
|
/*
|
|
|
|
* Add required objects into package dep's dictionary.
|
|
|
|
*/
|
2014-10-20 11:29:06 +05:30
|
|
|
if (autoinst && !xbps_dictionary_set_bool(pkgd, "automatic-install", true))
|
2020-02-10 04:50:13 +05:30
|
|
|
goto err;
|
2014-10-19 14:30:40 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a replaces to itself, so that virtual packages are always replaced.
|
|
|
|
*/
|
|
|
|
if ((replaces = xbps_dictionary_get(pkgd, "replaces")) == NULL)
|
|
|
|
replaces = xbps_array_create();
|
|
|
|
|
|
|
|
self_replaced = xbps_xasprintf("%s>=0", pkgname);
|
|
|
|
xbps_array_add_cstring(replaces, self_replaced);
|
|
|
|
free(self_replaced);
|
|
|
|
|
|
|
|
if (!xbps_dictionary_set(pkgd, "replaces", replaces))
|
2020-02-10 04:50:13 +05:30
|
|
|
goto err;
|
2014-10-19 14:30:40 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the dictionary into the unsorted queue.
|
|
|
|
*/
|
|
|
|
if (!xbps_array_add(pkgs, pkgd))
|
2020-02-10 04:50:13 +05:30
|
|
|
goto err;
|
|
|
|
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "repository", &repo);
|
2014-10-19 14:30:40 +05:30
|
|
|
|
2015-09-02 22:26:20 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_ADDPKG, 0, pkgver,
|
2020-02-21 13:38:22 +05:30
|
|
|
"Found %s in repository %s", pkgver, repo);
|
2014-10-19 14:30:40 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dbg_printf(xhp, "[trans] `%s' stored (%s)\n", pkgver, repo);
|
2020-01-06 17:17:13 +05:30
|
|
|
xbps_object_release(pkgd);
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
return true;
|
2020-02-10 04:50:13 +05:30
|
|
|
err:
|
|
|
|
xbps_object_release(pkgd);
|
2020-02-21 13:38:22 +05:30
|
|
|
return false;
|
2014-10-19 14:30:40 +05:30
|
|
|
}
|