|
|
|
|
@@ -37,22 +37,11 @@ struct transaction {
|
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
|
bool yes;
|
|
|
|
|
size_t inst_pkgcnt;
|
|
|
|
|
size_t up_pkgcnt;
|
|
|
|
|
size_t cf_pkgcnt;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int exec_transaction(struct transaction *);
|
|
|
|
|
static void show_missing_deps(prop_dictionary_t);
|
|
|
|
|
static int show_missing_dep_cb(prop_object_t, void *, bool *);
|
|
|
|
|
static void show_package_list(prop_object_iterator_t, const char *);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_missing_deps(prop_dictionary_t d)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"xbps-bin: unable to locate some required packages:\n");
|
|
|
|
|
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
|
|
|
|
|
show_missing_dep_cb, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
|
{
|
|
|
|
|
@@ -69,6 +58,15 @@ show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_missing_deps(prop_dictionary_t d)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"xbps-bin: unable to locate some required packages:\n");
|
|
|
|
|
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
|
|
|
|
|
show_missing_dep_cb, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
check_binpkg_hash(const char *path, const char *filename,
|
|
|
|
|
const char *sha256)
|
|
|
|
|
@@ -125,7 +123,7 @@ download_package_list(prop_object_iterator_t iter)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If package is in a local repository, check its hash
|
|
|
|
|
* and pass no next one.
|
|
|
|
|
* and pass to next one.
|
|
|
|
|
*/
|
|
|
|
|
if (!xbps_check_is_repo_string_remote(repoloc)) {
|
|
|
|
|
if (!check_binpkg_hash(lbinfile, filename, sha256)) {
|
|
|
|
|
@@ -167,11 +165,12 @@ download_package_list(prop_object_iterator_t iter)
|
|
|
|
|
rv = xbps_fetch_file(binfile, cachedir, false, NULL);
|
|
|
|
|
free(binfile);
|
|
|
|
|
if (rv == -1) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: couldn't download %s "
|
|
|
|
|
"from %s (%s)\n", filename, repoloc,
|
|
|
|
|
xbps_fetch_error_string());
|
|
|
|
|
fprintf(stderr, "xbps-bin: couldn't download `%s'\n",
|
|
|
|
|
filename);
|
|
|
|
|
fprintf(stderr, "xbps-bin: %s returned: `%s'\n",
|
|
|
|
|
repoloc, xbps_fetch_error_string());
|
|
|
|
|
free(lbinfile);
|
|
|
|
|
return errno;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!check_binpkg_hash(lbinfile, filename, sha256)) {
|
|
|
|
|
fprintf(stderr, "W: removing wrong %s file ...\n",
|
|
|
|
|
@@ -221,66 +220,62 @@ show_package_list(prop_object_iterator_t iter, const char *match)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
show_transaction_sizes(prop_object_iterator_t iter)
|
|
|
|
|
show_transaction_sizes(struct transaction *trans)
|
|
|
|
|
{
|
|
|
|
|
prop_object_t obj;
|
|
|
|
|
uint64_t tsize = 0, dlsize = 0, instsize = 0;
|
|
|
|
|
uint64_t dlsize = 0, instsize = 0;
|
|
|
|
|
const char *tract;
|
|
|
|
|
char size[64];
|
|
|
|
|
bool trans_inst, trans_up, trans_conf;
|
|
|
|
|
|
|
|
|
|
trans_inst = trans_up = trans_conf = false;
|
|
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
|
if (!prop_dictionary_get_uint64(obj, "filename-size", &tsize))
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
|
|
dlsize += tsize;
|
|
|
|
|
tsize = 0;
|
|
|
|
|
if (!prop_dictionary_get_uint64(obj, "installed_size", &tsize))
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
|
|
instsize += tsize;
|
|
|
|
|
tsize = 0;
|
|
|
|
|
}
|
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
|
|
|
|
while ((obj = prop_object_iterator_next(trans->iter))) {
|
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
|
"trans-action", &tract))
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
|
|
if (strcmp(tract, "install") == 0)
|
|
|
|
|
if (strcmp(tract, "install") == 0) {
|
|
|
|
|
trans->inst_pkgcnt++;
|
|
|
|
|
trans_inst = true;
|
|
|
|
|
else if (strcmp(tract, "update") == 0)
|
|
|
|
|
} else if (strcmp(tract, "update") == 0) {
|
|
|
|
|
trans->up_pkgcnt++;
|
|
|
|
|
trans_up = true;
|
|
|
|
|
else if (strcmp(tract, "configure") == 0)
|
|
|
|
|
} else if (strcmp(tract, "configure") == 0) {
|
|
|
|
|
trans->cf_pkgcnt++;
|
|
|
|
|
trans_conf = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
|
prop_object_iterator_reset(trans->iter);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Show the list of packages that will be installed.
|
|
|
|
|
*/
|
|
|
|
|
if (trans_inst) {
|
|
|
|
|
printf("The following packages will be installed:\n\n");
|
|
|
|
|
show_package_list(iter, "install");
|
|
|
|
|
show_package_list(trans->iter, "install");
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
}
|
|
|
|
|
if (trans_up) {
|
|
|
|
|
printf("The following packages will be updated:\n\n");
|
|
|
|
|
show_package_list(iter, "update");
|
|
|
|
|
show_package_list(trans->iter, "update");
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
}
|
|
|
|
|
if (trans_conf) {
|
|
|
|
|
printf("The following packages will be configured:\n\n");
|
|
|
|
|
show_package_list(iter, "configure");
|
|
|
|
|
show_package_list(trans->iter, "configure");
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Show total download/installed size for all required packages.
|
|
|
|
|
*/
|
|
|
|
|
if (!prop_dictionary_get_uint64(trans->dict,
|
|
|
|
|
"total-download-size", &dlsize))
|
|
|
|
|
return errno;
|
|
|
|
|
if (!prop_dictionary_get_uint64(trans->dict,
|
|
|
|
|
"total-installed-size", &instsize))
|
|
|
|
|
return errno;
|
|
|
|
|
if (xbps_humanize_number(size, 5, (int64_t)dlsize,
|
|
|
|
|
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error: humanize_number returns "
|
|
|
|
|
@@ -334,14 +329,14 @@ pkgname_from_pkgmatch(const char *pkg)
|
|
|
|
|
*
|
|
|
|
|
* XXX REALLY FIX THIS CRAP! I haven't found much easier ways...
|
|
|
|
|
*/
|
|
|
|
|
if ((version = xbps_get_pkgdep_version(pkg))) {
|
|
|
|
|
if ((version = xbps_get_pkgpattern_version(pkg))) {
|
|
|
|
|
while (*version) {
|
|
|
|
|
if (!isdigit((unsigned char)*version)) {
|
|
|
|
|
version++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (xbps_cmpver("0", version) <= 0)
|
|
|
|
|
return xbps_get_pkgdep_name(pkg);
|
|
|
|
|
return xbps_get_pkgpattern_name(pkg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((version = xbps_get_pkg_version(pkg))) {
|
|
|
|
|
@@ -394,7 +389,7 @@ xbps_install_new_pkg(const char *pkg)
|
|
|
|
|
/*
|
|
|
|
|
* Find a package in a repository and prepare for installation.
|
|
|
|
|
*/
|
|
|
|
|
if ((pkgd = xbps_find_pkg_installed_from_plist(pkgname))) {
|
|
|
|
|
if ((pkgd = xbps_find_pkg_dict_installed(pkgname, false))) {
|
|
|
|
|
printf("Package '%s' is already installed.\n", pkgname);
|
|
|
|
|
prop_object_release(pkgd);
|
|
|
|
|
if (pkgmatch)
|
|
|
|
|
@@ -424,7 +419,7 @@ xbps_update_pkg(const char *pkgname)
|
|
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
|
|
|
|
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
|
|
|
|
printf("Finding new '%s' package...\n", pkgname);
|
|
|
|
|
if (pkgd) {
|
|
|
|
|
rv = xbps_repository_update_pkg(pkgname, pkgd);
|
|
|
|
|
@@ -445,70 +440,12 @@ xbps_update_pkg(const char *pkgname)
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
xbps_exec_transaction(bool yes)
|
|
|
|
|
{
|
|
|
|
|
struct transaction *trans;
|
|
|
|
|
prop_array_t array;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
trans = calloc(1, sizeof(struct transaction));
|
|
|
|
|
if (trans == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
trans->dict = xbps_repository_get_transaction_dict();
|
|
|
|
|
if (trans->dict == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Bail out if there are unresolved deps.
|
|
|
|
|
*/
|
|
|
|
|
array = prop_dictionary_get(trans->dict, "missing_deps");
|
|
|
|
|
if (prop_array_count(array) > 0) {
|
|
|
|
|
show_missing_deps(trans->dict);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DPRINTF(("%s", prop_dictionary_externalize(trans->dict)));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sort the package transaction dictionary.
|
|
|
|
|
*/
|
|
|
|
|
if ((rv = xbps_sort_pkg_deps(trans->dict)) != 0) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error while sorting "
|
|
|
|
|
"packages: %s\n", strerror(rv));
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* It's time to run the transaction!
|
|
|
|
|
*/
|
|
|
|
|
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
|
|
|
|
if (trans->iter == NULL) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error allocating array mem! (%s)\n",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trans->yes = yes;
|
|
|
|
|
rv = exec_transaction(trans);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (trans->iter)
|
|
|
|
|
prop_object_iterator_release(trans->iter);
|
|
|
|
|
if (trans->dict)
|
|
|
|
|
prop_object_release(trans->dict);
|
|
|
|
|
if (trans)
|
|
|
|
|
free(trans);
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
replace_packages(prop_object_iterator_t iter, const char *pkgver)
|
|
|
|
|
{
|
|
|
|
|
prop_dictionary_t instd;
|
|
|
|
|
prop_object_t obj;
|
|
|
|
|
const char *reppkgn, *version;
|
|
|
|
|
const char *pattern, *reppkgn, *reppkgver, *version;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@@ -516,16 +453,23 @@ replace_packages(prop_object_iterator_t iter, const char *pkgver)
|
|
|
|
|
* them before upgrading or installing new one.
|
|
|
|
|
*/
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
|
|
|
|
reppkgn = prop_string_cstring_nocopy(obj);
|
|
|
|
|
if (reppkgn == NULL)
|
|
|
|
|
pattern = prop_string_cstring_nocopy(obj);
|
|
|
|
|
if (pattern == NULL)
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
|
|
instd = xbps_find_pkg_installed_from_plist(reppkgn);
|
|
|
|
|
/*
|
|
|
|
|
* If pattern matches an installed package, replace it.
|
|
|
|
|
*/
|
|
|
|
|
instd = xbps_find_pkg_dict_installed(pattern, true);
|
|
|
|
|
if (instd == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
printf("Replacing package '%s' with '%s' ...\n",
|
|
|
|
|
reppkgn, pkgver);
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(instd, "pkgname", &reppkgn);
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(instd, "pkgver", &reppkgver);
|
|
|
|
|
printf("Replacing package '%s' with '%s' "
|
|
|
|
|
"(matched by '%s')...\n", reppkgver, pkgver, pattern);
|
|
|
|
|
prop_object_release(instd);
|
|
|
|
|
|
|
|
|
|
version = xbps_get_pkg_version(pkgver);
|
|
|
|
|
if ((rv = xbps_remove_pkg(reppkgn, version, false)) != 0) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: couldn't remove %s (%s)\n",
|
|
|
|
|
@@ -562,8 +506,7 @@ exec_transaction(struct transaction *trans)
|
|
|
|
|
/*
|
|
|
|
|
* Show download/installed size for the transaction.
|
|
|
|
|
*/
|
|
|
|
|
rv = show_transaction_sizes(trans->iter);
|
|
|
|
|
if (rv != 0)
|
|
|
|
|
if ((rv = show_transaction_sizes(trans)) != 0)
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@@ -580,12 +523,14 @@ exec_transaction(struct transaction *trans)
|
|
|
|
|
* Download binary packages (if they come from a remote repository)
|
|
|
|
|
* and check its SHA256 hash.
|
|
|
|
|
*/
|
|
|
|
|
printf("[1/3] Downloading/integrity check\n\n");
|
|
|
|
|
if ((rv = download_package_list(trans->iter)) != 0)
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Iterate over the transaction dictionary.
|
|
|
|
|
*/
|
|
|
|
|
printf("\n[2/3] Unpacking\n\n");
|
|
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
|
"pkgname", &pkgname))
|
|
|
|
|
@@ -631,7 +576,7 @@ exec_transaction(struct transaction *trans)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(tract, "update") == 0) {
|
|
|
|
|
instpkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
|
|
|
|
instpkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
|
|
|
|
if (instpkgd == NULL) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error: unable to "
|
|
|
|
|
"find %s installed dict!\n", pkgname);
|
|
|
|
|
@@ -648,27 +593,24 @@ exec_transaction(struct transaction *trans)
|
|
|
|
|
/*
|
|
|
|
|
* If package is marked as 'essential' remove old
|
|
|
|
|
* requiredby entries and overwrite pkg files; otherwise
|
|
|
|
|
* remove old package and install new one.
|
|
|
|
|
* remove old package and install new one. This
|
|
|
|
|
* is all handled internally in xbps_remove_pkg()
|
|
|
|
|
* and xbps_unpack_binary_pkg().
|
|
|
|
|
*/
|
|
|
|
|
if (essential) {
|
|
|
|
|
rv = xbps_requiredby_pkg_remove(pkgname);
|
|
|
|
|
if (rv != 0) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error: "
|
|
|
|
|
"couldn't remove reqby"
|
|
|
|
|
" entries for %s-%s (%s)\n",
|
|
|
|
|
pkgname, instver, strerror(rv));
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
printf("Removing %s-%s ...\n",
|
|
|
|
|
pkgname, instver);
|
|
|
|
|
rv = xbps_remove_pkg(pkgname, version, true);
|
|
|
|
|
if (rv != 0) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error "
|
|
|
|
|
"removing %s-%s (%s)\n",
|
|
|
|
|
pkgname, instver, strerror(rv));
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
if (essential)
|
|
|
|
|
printf("Replacing %s-%s with %s-%s ...\n",
|
|
|
|
|
pkgname, instver, pkgname, version);
|
|
|
|
|
else
|
|
|
|
|
printf("Removing %s-%s before installing new "
|
|
|
|
|
"version ...\n", pkgname, instver);
|
|
|
|
|
|
|
|
|
|
rv = xbps_remove_pkg(pkgname, version, true);
|
|
|
|
|
if (rv != 0) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error "
|
|
|
|
|
"%s %s-%s (%s)\n", essential ?
|
|
|
|
|
"replacing" : "removing", pkgname,
|
|
|
|
|
instver, strerror(rv));
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
@@ -694,6 +636,7 @@ exec_transaction(struct transaction *trans)
|
|
|
|
|
/*
|
|
|
|
|
* Configure all unpacked packages.
|
|
|
|
|
*/
|
|
|
|
|
printf("\n[3/3] Configuring\n\n");
|
|
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
|
"pkgname", &pkgname))
|
|
|
|
|
@@ -713,7 +656,60 @@ exec_transaction(struct transaction *trans)
|
|
|
|
|
"package %s (%s)\n", pkgname, strerror(rv));
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
trans->cf_pkgcnt++;
|
|
|
|
|
}
|
|
|
|
|
printf("\nxbps-bin: %zu installed, %zu updated, "
|
|
|
|
|
"%zu configured.\n", trans->inst_pkgcnt, trans->up_pkgcnt,
|
|
|
|
|
trans->cf_pkgcnt);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
xbps_exec_transaction(bool yes)
|
|
|
|
|
{
|
|
|
|
|
struct transaction *trans;
|
|
|
|
|
prop_array_t array;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
trans = calloc(1, sizeof(struct transaction));
|
|
|
|
|
if (trans == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
trans->dict = xbps_repository_get_transaction_dict();
|
|
|
|
|
if (trans->dict == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Bail out if there are unresolved deps.
|
|
|
|
|
*/
|
|
|
|
|
array = prop_dictionary_get(trans->dict, "missing_deps");
|
|
|
|
|
if (prop_array_count(array) > 0) {
|
|
|
|
|
show_missing_deps(trans->dict);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DPRINTF(("%s", prop_dictionary_externalize(trans->dict)));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* It's time to run the transaction!
|
|
|
|
|
*/
|
|
|
|
|
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
|
|
|
|
if (trans->iter == NULL) {
|
|
|
|
|
fprintf(stderr, "xbps-bin: error allocating array mem! (%s)\n",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trans->yes = yes;
|
|
|
|
|
rv = exec_transaction(trans);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (trans->iter)
|
|
|
|
|
prop_object_iterator_release(trans->iter);
|
|
|
|
|
if (trans->dict)
|
|
|
|
|
prop_object_release(trans->dict);
|
|
|
|
|
if (trans)
|
|
|
|
|
free(trans);
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|