Remove knowledge from the library to install packages.
The library is only responsible now to find all binary packages from repositories, sort them and create a dictionary with all details. The frontend (xbps-bin) provides support for this, and this allows for more flexibility and removes some stuff that didn't belong in the library. While here implemented support to show total download/installed size for all packages that are going to be installed. Next step will be to implement user interactivity before installing/removing/updating packages. --HG-- extra : convert_revision : 858e9a89bc6a60b348435f2416a8af3ebb6ea5c9
This commit is contained in:
parent
acd07f61e3
commit
f80e1753a8
13 changed files with 580 additions and 482 deletions
|
@ -34,11 +34,10 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/util.h"
|
||||
|
||||
static void usage(void);
|
||||
static void show_missing_deps(prop_dictionary_t, const char *);
|
||||
static int show_missing_dep_cb(prop_object_t, void *, bool *);
|
||||
static int list_pkgs_in_dict(prop_object_t, void *, bool *);
|
||||
|
||||
static void
|
||||
|
@ -87,34 +86,7 @@ list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
|||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc);
|
||||
if (pkgname && version && short_desc) {
|
||||
printf("%s (%s)\t%s\n", pkgname, version, short_desc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static void
|
||||
show_missing_deps(prop_dictionary_t d, const char *pkgname)
|
||||
{
|
||||
printf("Unable to locate some required packages for %s:\n",
|
||||
pkgname);
|
||||
(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)
|
||||
{
|
||||
const char *pkgname, *version;
|
||||
(void)arg;
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
if (pkgname && version) {
|
||||
printf("\tmissing binary package for: %s >= %s\n",
|
||||
pkgname, version);
|
||||
printf("%s-%s\t%s\n", pkgname, version, short_desc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -196,41 +168,14 @@ main(int argc, char **argv)
|
|||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = xbps_install_binary_pkg(argv[1], false);
|
||||
if (rv != 0) {
|
||||
if (rv == EAGAIN) {
|
||||
printf("Unable to locate %s in "
|
||||
"repository pool.\n", argv[1]);
|
||||
} else if (rv == ENOENT) {
|
||||
dict = xbps_get_pkg_deps_dictionary();
|
||||
if (dict)
|
||||
show_missing_deps(dict, argv[1]);
|
||||
} else if (rv == EEXIST) {
|
||||
printf("Package '%s' is already up to date.\n",
|
||||
argv[1]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("Package %s installed successfully.\n", argv[1]);
|
||||
xbps_install_pkg(argv[1], false);
|
||||
|
||||
} else if (strcasecmp(argv[0], "update") == 0) {
|
||||
/* Update an installed package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = xbps_install_binary_pkg(argv[1], true);
|
||||
if (rv != 0) {
|
||||
if (rv == EEXIST) {
|
||||
printf("Package %s is already up to date.\n",
|
||||
argv[1]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Package %s updated successfully.\n", argv[1]);
|
||||
xbps_install_pkg(argv[1], true);
|
||||
|
||||
} else if (strcasecmp(argv[0], "remove") == 0) {
|
||||
/* Removes a binary package. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue