From 746d59a9dd25f1a5bacd58d06d43db02a1ef5ce3 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 15 Feb 2009 20:23:23 +0100 Subject: [PATCH] Some improvements for installation of binary packages. * If any dep of a package cannot be found in the repository pool, show it on xbps-bin. * Add the automatic-install boolean obj into pkg's dictionary on regpkgdb.plist, this will be used to implemented something like "apt-get autoremove". --HG-- extra : convert_revision : 666e2fa666ac94140159896e28b445e88e8afb7a --- bin/xbps-bin/main.c | 33 ++++++++++++++++++++++++++++++--- bin/xbps-pkgdb/main.c | 3 ++- include/install.h | 4 +++- lib/depends.c | 13 ++++++++++++- lib/install.c | 26 ++++++++++++++++++++++---- 5 files changed, 69 insertions(+), 10 deletions(-) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 70eb6de587f..fb00fb4e668 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -35,6 +35,8 @@ #include 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 @@ -77,6 +79,31 @@ list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done) 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; + + 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); + return 0; + } + + return EINVAL; +} + int main(int argc, char **argv) { @@ -138,12 +165,12 @@ main(int argc, char **argv) if (strcasecmp(argv[0], "install") == 0) { rv = xbps_install_binary_pkg(argv[1], root); if (rv) { - if (errno == ENOENT) + dict = xbps_get_pkg_deps_dictionary(); + if (dict == NULL && errno == ENOENT) printf("Unable to locate %s in " "repository pool.\n", argv[1]); else - printf("Unable to install %s (%s).\n", - argv[1], strerror(errno)); + show_missing_deps(dict, argv[1]); exit(EXIT_FAILURE); } printf("Package %s installed successfully.\n", argv[1]); diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index 04ea59a62bc..d4e1cc177e0 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -113,7 +113,8 @@ main(int argc, char **argv) if (argc != 4) usage(); - rv = xbps_register_pkg(NULL, argv[1], argv[2], argv[3]); + rv = xbps_register_pkg(NULL, argv[1], argv[2], + argv[3], false); if (rv == EEXIST) { printf("%s=> %s-%s already registered.\n", in_chroot ? "[chroot] " : "", argv[1], argv[2]); diff --git a/include/install.h b/include/install.h index ffac453fed9..1f5856c039c 100644 --- a/include/install.h +++ b/include/install.h @@ -32,13 +32,15 @@ int xbps_install_binary_pkg(const char *, const char *); int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t, const char *); int xbps_register_pkg(prop_dictionary_t, const char *, const char *, - const char *); + const char *, bool); int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t, const char *, void (*cb_print)(prop_dictionary_t)); int xbps_update_pkg_requiredby(prop_array_t, prop_dictionary_t); int xbps_find_deps_in_pkg(prop_dictionary_t); +prop_dictionary_t xbps_get_pkg_deps_dictionary(void); + /* From lib/sortdeps.c */ int xbps_sort_pkg_deps(prop_dictionary_t); diff --git a/lib/depends.c b/lib/depends.c index 9d496690e67..3770d5b74fd 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -40,6 +40,7 @@ static int find_pkg_missing_deps_from_repo(prop_dictionary_t, prop_dictionary_t); static prop_dictionary_t chaindeps; +static bool deps_dict; /* * Creates the dictionary to store the dependency chain. @@ -369,6 +370,7 @@ xbps_find_deps_in_pkg(prop_dictionary_t pkg) missing_rdeps = prop_dictionary_get(chaindeps, "missing_deps"); if (prop_array_count(missing_rdeps) == 0) goto out; + /* * If there are missing deps, iterate one more time * just in case that indirect deps weren't found. @@ -405,6 +407,15 @@ out: return rv; } +prop_dictionary_t +xbps_get_pkg_deps_dictionary(void) +{ + if (!deps_dict) + return NULL; + + return prop_dictionary_copy(chaindeps); +} + static int find_pkg_missing_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg) { @@ -473,7 +484,6 @@ find_pkg_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg, const char *reqpkg, *reqvers; char *pkgname; int rv = 0; - static bool deps_dict; /* * Package doesn't have deps, check to be sure. @@ -602,6 +612,7 @@ xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir) if (required == NULL) return 0; + iter = prop_array_iterator(required); if (iter == NULL) return ENOMEM; diff --git a/lib/install.c b/lib/install.c index 2efe0e8320a..e1166d3092d 100644 --- a/lib/install.c +++ b/lib/install.c @@ -47,6 +47,7 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg, { const char *pkgname, *version, *desc; int rv = 0; + bool automatic = false; assert(pkg != NULL); prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname); @@ -56,9 +57,12 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg, assert(version != NULL); assert(desc != NULL); + if (repo == false) + automatic = true; + rv = xbps_unpack_binary_pkg(repo, pkg, destdir, NULL); if (rv == 0) { - rv = xbps_register_pkg(pkg, pkgname, version, desc); + rv = xbps_register_pkg(pkg, pkgname, version, desc, automatic); if (rv == EEXIST) rv = 0; } @@ -87,6 +91,8 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir) */ rv = xbps_callback_array_iter_in_repolist(install_binpkg_repo_cb, (void *)&cb); + if (rv == 0 && errno == ENOENT) + rv = errno; return rv; } @@ -139,9 +145,10 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done) */ if ((rv = xbps_find_deps_in_pkg(pkgrd)) != 0) { prop_object_release(repod); - if (rv == ENOENT) + if (rv == ENOENT) { + errno = ENOENT; return 0; - + } return rv; } @@ -155,6 +162,10 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done) *cbloop_done = true; } + /* Cleanup errno, just in case */ + if (rv == 0) + errno = 0; + return rv; } @@ -175,7 +186,8 @@ make_dict_from_pkg(const char *name, const char *ver, const char *desc) int xbps_register_pkg(prop_dictionary_t pkgrd, const char *pkgname, - const char *version, const char *desc) + const char *version, const char *desc, + bool automatic) { prop_dictionary_t dict, pkgd; prop_array_t array; @@ -212,6 +224,9 @@ xbps_register_pkg(prop_dictionary_t pkgrd, const char *pkgname, goto out; } + prop_dictionary_set_bool(pkgd, "automatic-install", + automatic); + if (!xbps_add_obj_to_dict(dict, array, "packages")) { prop_object_release(array); rv = EINVAL; @@ -234,6 +249,9 @@ xbps_register_pkg(prop_dictionary_t pkgrd, const char *pkgname, goto out; } + prop_dictionary_set_bool(pkgd, "automatic-install", + automatic); + if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) { rv = xbps_update_pkg_requiredby(array, pkgrd); if (rv != 0) {