diff --git a/bin/xbps-bin/Makefile b/bin/xbps-bin/Makefile index 8dfd2351..eac22291 100644 --- a/bin/xbps-bin/Makefile +++ b/bin/xbps-bin/Makefile @@ -8,6 +8,7 @@ OBJS += question.o fetch_cb.o state_cb.o OBJS += check.o check_pkg_automatic.o check_pkg_files.o OBJS += check_pkg_rundeps.o check_pkg_symlinks.o OBJS += check_pkg_requiredby.o +OBJS += show-orphans.o unpack_cb.o list.o MAN = $(BIN).8 include $(TOPDIR)/bin/prog.mk diff --git a/bin/xbps-bin/defs.h b/bin/xbps-bin/defs.h index 8714d029..a7f8c30f 100644 --- a/bin/xbps-bin/defs.h +++ b/bin/xbps-bin/defs.h @@ -38,6 +38,11 @@ struct xferstat { struct timeval last; }; +struct list_pkgver_cb { + pkg_state_t state; + size_t pkgver_len; +}; + /* from install.c */ int install_new_pkg(const char *); int update_pkg(const char *); @@ -69,6 +74,9 @@ int show_pkg_reverse_deps(const char *); int show_pkg_info_from_metadir(const char *, const char *); int show_pkg_files_from_metadir(const char *); +/* from show-orphans.c */ +int show_orphans(void); + /* from find-files.c */ int find_files_in_packages(const char *); @@ -82,6 +90,10 @@ void fetch_file_progress_cb(struct xbps_fetch_cb_data *); /* from state_cb.c */ void state_cb(struct xbps_state_cb_data *); +/* from unpack_cb.c */ +void unpack_progress_cb_verbose(struct xbps_unpack_cb_data *); +void unpack_progress_cb(struct xbps_unpack_cb_data *); + /* From util.c */ int show_pkg_files(prop_dictionary_t); void show_pkg_info(prop_dictionary_t); @@ -92,4 +104,8 @@ int list_strings_sep_in_array(prop_object_t, void *, bool *); size_t find_longest_pkgver(prop_dictionary_t); void print_package_line(const char *, bool); +/* from list.c */ +int list_pkgs_in_dict(prop_object_t, void *, bool *); +int list_manual_pkgs(prop_object_t, void *, bool *); + #endif /* !_XBPS_BIN_DEFS_H_ */ diff --git a/bin/xbps-bin/list.c b/bin/xbps-bin/list.c new file mode 100644 index 00000000..ed04e312 --- /dev/null +++ b/bin/xbps-bin/list.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2008-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 +#include +#include +#include +#include + +#include "defs.h" +#include "compat.h" + +int +list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done) +{ + struct list_pkgver_cb *lpc = arg; + const char *pkgver, *short_desc; + char *tmp = NULL; + pkg_state_t curstate; + size_t i = 0; + + (void)loop_done; + + if (xbps_pkg_state_dictionary(obj, &curstate)) + return EINVAL; + + if (lpc->state == 0) { + /* Only list packages that are fully installed */ + if (curstate != XBPS_PKG_STATE_INSTALLED) + return 0; + } else { + /* Only list packages with specified state */ + if (curstate != lpc->state) + return 0; + } + + prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); + prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); + if (!pkgver && !short_desc) + return EINVAL; + + tmp = calloc(1, lpc->pkgver_len + 1); + if (tmp == NULL) + return errno; + + strlcpy(tmp, pkgver, lpc->pkgver_len + 1); + for (i = strlen(tmp); i < lpc->pkgver_len; i++) + tmp[i] = ' '; + + printf("%s %s\n", tmp, short_desc); + free(tmp); + + return 0; +} + +int +list_manual_pkgs(prop_object_t obj, void *arg, bool *loop_done) +{ + const char *pkgver; + bool automatic = false; + + (void)arg; + (void)loop_done; + + prop_dictionary_get_bool(obj, "automatic-install", &automatic); + if (automatic == false) { + prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); + printf("%s\n", pkgver); + } + + return 0; +} diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index a12029d3..dc72d18d 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -38,11 +38,6 @@ #include "defs.h" #include "../xbps-repo/defs.h" -struct list_pkgver_cb { - pkg_state_t state; - size_t pkgver_len; -}; - static void __attribute__((noreturn)) usage(struct xbps_handle *xhp) { @@ -55,95 +50,6 @@ usage(struct xbps_handle *xhp) exit(EXIT_FAILURE); } -static int -list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done) -{ - struct list_pkgver_cb *lpc = arg; - const char *pkgver, *short_desc; - char *tmp = NULL; - pkg_state_t curstate; - size_t i = 0; - - (void)loop_done; - - if (xbps_pkg_state_dictionary(obj, &curstate)) - return EINVAL; - - if (lpc->state == 0) { - /* Only list packages that are fully installed */ - if (curstate != XBPS_PKG_STATE_INSTALLED) - return 0; - } else { - /* Only list packages with specified state */ - if (curstate != lpc->state) - return 0; - } - - prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); - prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); - if (!pkgver && !short_desc) - return EINVAL; - - tmp = calloc(1, lpc->pkgver_len + 1); - if (tmp == NULL) - return errno; - - strlcpy(tmp, pkgver, lpc->pkgver_len + 1); - for (i = strlen(tmp); i < lpc->pkgver_len; i++) - tmp[i] = ' '; - - printf("%s %s\n", tmp, short_desc); - free(tmp); - - return 0; -} - -static int -list_manual_packages(prop_object_t obj, void *arg, bool *loop_done) -{ - const char *pkgver; - bool automatic = false; - - (void)arg; - (void)loop_done; - - prop_dictionary_get_bool(obj, "automatic-install", &automatic); - if (automatic == false) { - prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); - printf("%s\n", pkgver); - } - - return 0; -} - -static int -show_orphans(void) -{ - prop_array_t orphans; - prop_object_iterator_t iter; - prop_object_t obj; - const char *pkgver; - - orphans = xbps_find_pkg_orphans(NULL); - if (orphans == NULL) - return EINVAL; - - if (prop_array_count(orphans) == 0) - return 0; - - iter = prop_array_iterator(orphans); - if (iter == NULL) - return ENOMEM; - - while ((obj = prop_object_iterator_next(iter)) != NULL) { - prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); - printf("%s\n", pkgver); - } - prop_object_iterator_release(iter); - - return 0; -} - static void __attribute__((noreturn)) cleanup(int signum) { @@ -153,31 +59,6 @@ cleanup(int signum) exit(signum); } -static void -unpack_progress_cb_verbose(struct xbps_unpack_cb_data *xpd) -{ - if (xpd->entry == NULL || xpd->entry_is_metadata) - return; - else if (xpd->entry_size <= 0) - return; - - printf("Extracted %sfile `%s' (%" PRIi64 " bytes)\n", - xpd->entry_is_conf ? "configuration " : "", xpd->entry, - xpd->entry_size); -} - -static void -unpack_progress_cb(struct xbps_unpack_cb_data *xpd) -{ - if (xpd->entry == NULL || xpd->entry_is_metadata) - return; - else if (xpd->entry_size <= 0) - return; - - printf("Extracting `%s'...\n", xpd->entry); - printf("\033[1A\033[K"); -} - int main(int argc, char **argv) { @@ -476,7 +357,7 @@ main(int argc, char **argv) usage(xhp); rv = xbps_callback_array_iter_in_dict(xhp->regpkgdb_dictionary, - "packages", list_manual_packages, NULL); + "packages", list_manual_pkgs, NULL); } else if (strcasecmp(argv[0], "show-revdeps") == 0) { /* diff --git a/bin/xbps-bin/show-orphans.c b/bin/xbps-bin/show-orphans.c new file mode 100644 index 00000000..ad86ce7a --- /dev/null +++ b/bin/xbps-bin/show-orphans.c @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2008-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 +#include +#include + +#include "defs.h" + +int +show_orphans(void) +{ + prop_array_t orphans; + prop_object_iterator_t iter; + prop_object_t obj; + const char *pkgver; + + orphans = xbps_find_pkg_orphans(NULL); + if (orphans == NULL) + return EINVAL; + + if (prop_array_count(orphans) == 0) + return 0; + + iter = prop_array_iterator(orphans); + if (iter == NULL) + return ENOMEM; + + while ((obj = prop_object_iterator_next(iter)) != NULL) { + prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); + printf("%s\n", pkgver); + } + prop_object_iterator_release(iter); + + return 0; +} diff --git a/bin/xbps-bin/unpack_cb.c b/bin/xbps-bin/unpack_cb.c new file mode 100644 index 00000000..3a85c62f --- /dev/null +++ b/bin/xbps-bin/unpack_cb.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2008-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 +#include +#include + +#include "defs.h" + +void +unpack_progress_cb_verbose(struct xbps_unpack_cb_data *xpd) +{ + if (xpd->entry == NULL || xpd->entry_is_metadata) + return; + else if (xpd->entry_size <= 0) + return; + + printf("Extracted %sfile `%s' (%" PRIi64 " bytes)\n", + xpd->entry_is_conf ? "configuration " : "", xpd->entry, + xpd->entry_size); +} + +void +unpack_progress_cb(struct xbps_unpack_cb_data *xpd) +{ + if (xpd->entry == NULL || xpd->entry_is_metadata) + return; + else if (xpd->entry_size <= 0) + return; + + printf("Extracting `%s'...\n", xpd->entry); + printf("\033[1A\033[K"); +}