From 3a65c45de317e1c07703f24575c34edd2b7372a7 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 24 Nov 2009 11:05:39 +0000 Subject: [PATCH] Refactored shared code between xbps-bin(8) and xbps-repo(8). - xbps-repo: move protos to defs.h and remove index.h and util.h. - xbps-bin: move code that belongs to it from xbps-repo to show-info-files.c. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091124110539-nsdjp0ajr7nn8pa3 --- bin/xbps-bin/Makefile | 4 +- bin/xbps-bin/defs.h | 2 + bin/xbps-bin/main.c | 2 +- bin/xbps-bin/remove.c | 2 +- bin/xbps-bin/show-deps.c | 2 +- bin/xbps-bin/show-info-files.c | 135 ++++++++++++++++++++++++++++++ bin/xbps-repo/{index.h => defs.h} | 12 ++- bin/xbps-repo/index.c | 2 +- bin/xbps-repo/main.c | 3 +- bin/xbps-repo/util.c | 102 +--------------------- bin/xbps-repo/util.h | 36 -------- 11 files changed, 154 insertions(+), 148 deletions(-) create mode 100644 bin/xbps-bin/show-info-files.c rename bin/xbps-repo/{index.h => defs.h} (80%) delete mode 100644 bin/xbps-repo/util.h diff --git a/bin/xbps-bin/Makefile b/bin/xbps-bin/Makefile index 3a3ffe99..a6e4f6bc 100644 --- a/bin/xbps-bin/Makefile +++ b/bin/xbps-bin/Makefile @@ -2,8 +2,8 @@ TOPDIR = ../.. include $(TOPDIR)/vars.mk BIN = xbps-bin -OBJS = check.o install.o main.o remove.o show-deps.o ../xbps-repo/util.o +OBJS = check.o install.o main.o remove.o show-deps.o +OBJS += show-info-files.o ../xbps-repo/util.o MAN = $(BIN).8 include $(TOPDIR)/prog.mk - diff --git a/bin/xbps-bin/defs.h b/bin/xbps-bin/defs.h index a6fe8669..754c07a7 100644 --- a/bin/xbps-bin/defs.h +++ b/bin/xbps-bin/defs.h @@ -33,5 +33,7 @@ int xbps_check_pkg_integrity(const char *); int xbps_check_pkg_integrity_all(void); int xbps_show_pkg_deps(const char *); int xbps_show_pkg_reverse_deps(const char *); +int show_pkg_info_from_metadir(const char *); +int show_pkg_files_from_metadir(const char *); #endif /* !_XBPS_BIN_DEFS_H_ */ diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index d4a4d97d..7ed0c1bc 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -32,7 +32,7 @@ #include #include "defs.h" -#include "../xbps-repo/util.h" +#include "../xbps-repo/defs.h" static void cleanup(int); static void usage(void); diff --git a/bin/xbps-bin/remove.c b/bin/xbps-bin/remove.c index 3930a488..e66aef26 100644 --- a/bin/xbps-bin/remove.c +++ b/bin/xbps-bin/remove.c @@ -31,7 +31,7 @@ #include #include "defs.h" -#include "../xbps-repo/util.h" +#include "../xbps-repo/defs.h" int xbps_autoremove_pkgs(void) diff --git a/bin/xbps-bin/show-deps.c b/bin/xbps-bin/show-deps.c index f1af7543..8360562f 100644 --- a/bin/xbps-bin/show-deps.c +++ b/bin/xbps-bin/show-deps.c @@ -30,8 +30,8 @@ #include #include -#include "../xbps-repo/util.h" #include "defs.h" +#include "../xbps-repo/defs.h" int xbps_show_pkg_deps(const char *pkgname) diff --git a/bin/xbps-bin/show-info-files.c b/bin/xbps-bin/show-info-files.c new file mode 100644 index 00000000..7bc42fcc --- /dev/null +++ b/bin/xbps-bin/show-info-files.c @@ -0,0 +1,135 @@ +/*- + * Copyright (c) 2008-2009 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 + +#include +#include "../xbps-repo/defs.h" +#include "defs.h" + +int +show_pkg_info_from_metadir(const char *pkgname) +{ + prop_dictionary_t pkgd; + char *plist; + + plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), + XBPS_META_PATH, pkgname, XBPS_PKGPROPS); + if (plist == NULL) + return EINVAL; + + pkgd = prop_dictionary_internalize_from_file(plist); + if (pkgd == NULL) { + free(plist); + return errno; + } + + show_pkg_info(pkgd); + prop_object_release(pkgd); + free(plist); + + return 0; +} + +int +show_pkg_files_from_metadir(const char *pkgname) +{ + prop_dictionary_t pkgd; + prop_array_t array; + prop_object_iterator_t iter = NULL; + prop_object_t obj; + const char *file; + char *plist, *array_str = "files"; + int i, rv = 0; + + plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), + XBPS_META_PATH, pkgname, XBPS_PKGFILES); + if (plist == NULL) + return EINVAL; + + pkgd = prop_dictionary_internalize_from_file(plist); + if (pkgd == NULL) { + free(plist); + return errno; + } + free(plist); + + /* Links. */ + array = prop_dictionary_get(pkgd, "links"); + if (array && prop_array_count(array) > 0) { + iter = xbps_get_array_iter_from_dict(pkgd, "links"); + if (iter == NULL) { + rv = EINVAL; + goto out; + } + while ((obj = prop_object_iterator_next(iter))) { + if (!prop_dictionary_get_cstring_nocopy(obj, + "file", &file)) { + prop_object_iterator_release(iter); + rv = errno; + goto out; + } + printf("%s\n", file); + } + prop_object_iterator_release(iter); + } + + /* Files and configuration files. */ + for (i = 0; i < 2; i++) { + if (i == 0) + array_str = "conf_files"; + else + array_str = "files"; + + array = prop_dictionary_get(pkgd, array_str); + if (array == NULL || prop_array_count(array) == 0) + continue; + + iter = xbps_get_array_iter_from_dict(pkgd, array_str); + if (iter == NULL) { + rv = EINVAL; + goto out; + } + while ((obj = prop_object_iterator_next(iter))) { + if (!prop_dictionary_get_cstring_nocopy(obj, + "file", &file)) { + prop_object_iterator_release(iter); + rv = errno; + goto out; + } + printf("%s\n", file); + } + prop_object_iterator_release(iter); + } +out: + prop_object_release(pkgd); + + return rv; +} diff --git a/bin/xbps-repo/index.h b/bin/xbps-repo/defs.h similarity index 80% rename from bin/xbps-repo/index.h rename to bin/xbps-repo/defs.h index f21a6576..47c29e9d 100644 --- a/bin/xbps-repo/index.h +++ b/bin/xbps-repo/defs.h @@ -23,10 +23,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _XBPS_REPO_INDEX_H_ -#define _XBPS_REPO_INDEX_H_ +#ifndef _XBPS_REPO_DEFS_H_ +#define _XBPS_REPO_DEFS_H_ +/* From index.c */ int xbps_repo_genindex(const char *); int xbps_repo_addpkg_index(prop_dictionary_t, const char *, const char *); +/* From util.c */ +void show_pkg_info(prop_dictionary_t); +int show_pkg_namedesc(prop_object_t, void *, bool *); +int list_strings_in_array(prop_object_t, void *, bool *); +int list_strings_sep_in_array(prop_object_t, void *, bool *); -#endif /* !_XBPS_REPO_INDEX_H_ */ +#endif /* !_XBPS_REPO_DEFS_H_ */ diff --git a/bin/xbps-repo/index.c b/bin/xbps-repo/index.c index b8803e52..4eae7b10 100644 --- a/bin/xbps-repo/index.c +++ b/bin/xbps-repo/index.c @@ -33,7 +33,7 @@ #include #include -#include "index.h" +#include "defs.h" /* Array of valid architectures */ static const char *archdirs[] = { "i686", "x86_64", "noarch", NULL }; diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index dfdeff24..29cd7e48 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -32,8 +32,7 @@ #include #include -#include "index.h" -#include "util.h" +#include "defs.h" static bool sanitize_localpath(char *, const char *); static int pkgindex_verify(const char *, const char *, bool); diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index 5f8c70d8..ce718636 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -31,7 +31,7 @@ #include #include -#include "util.h" +#include "defs.h" void show_pkg_info(prop_dictionary_t dict) @@ -112,106 +112,6 @@ show_pkg_info(prop_dictionary_t dict) printf(" %s\n", prop_string_cstring_nocopy(obj)); } -int -show_pkg_info_from_metadir(const char *pkgname) -{ - prop_dictionary_t pkgd; - char *plist; - - plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGPROPS); - if (plist == NULL) - return EINVAL; - - pkgd = prop_dictionary_internalize_from_file(plist); - if (pkgd == NULL) { - free(plist); - return errno; - } - - show_pkg_info(pkgd); - prop_object_release(pkgd); - free(plist); - - return 0; -} - -int -show_pkg_files_from_metadir(const char *pkgname) -{ - prop_dictionary_t pkgd; - prop_array_t array; - prop_object_iterator_t iter = NULL; - prop_object_t obj; - const char *file; - char *plist, *array_str = "files"; - int i, rv = 0; - - plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGFILES); - if (plist == NULL) - return EINVAL; - - pkgd = prop_dictionary_internalize_from_file(plist); - if (pkgd == NULL) { - free(plist); - return errno; - } - free(plist); - - /* Links. */ - array = prop_dictionary_get(pkgd, "links"); - if (array && prop_array_count(array) > 0) { - iter = xbps_get_array_iter_from_dict(pkgd, "links"); - if (iter == NULL) { - rv = EINVAL; - goto out; - } - while ((obj = prop_object_iterator_next(iter))) { - if (!prop_dictionary_get_cstring_nocopy(obj, - "file", &file)) { - prop_object_iterator_release(iter); - rv = errno; - goto out; - } - printf("%s\n", file); - } - prop_object_iterator_release(iter); - } - - /* Files and configuration files. */ - for (i = 0; i < 2; i++) { - if (i == 0) - array_str = "conf_files"; - else - array_str = "files"; - - array = prop_dictionary_get(pkgd, array_str); - if (array == NULL || prop_array_count(array) == 0) - continue; - - iter = xbps_get_array_iter_from_dict(pkgd, array_str); - if (iter == NULL) { - rv = EINVAL; - goto out; - } - while ((obj = prop_object_iterator_next(iter))) { - if (!prop_dictionary_get_cstring_nocopy(obj, - "file", &file)) { - prop_object_iterator_release(iter); - rv = errno; - goto out; - } - printf("%s\n", file); - } - prop_object_iterator_release(iter); - } -out: - prop_object_release(pkgd); - - return rv; -} - int show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) { diff --git a/bin/xbps-repo/util.h b/bin/xbps-repo/util.h deleted file mode 100644 index 7294f6c4..00000000 --- a/bin/xbps-repo/util.h +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * Copyright (c) 2008-2009 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. - */ - -#ifndef _XBPS_REPO_UTIL_H_ -#define _XBPS_REPO_UTIL_H_ - -void show_pkg_info(prop_dictionary_t); -int show_pkg_info_from_metadir(const char *); -int show_pkg_files_from_metadir(const char *); -int show_pkg_namedesc(prop_object_t, void *, bool *); -int list_strings_in_array(prop_object_t, void *, bool *); -int list_strings_sep_in_array(prop_object_t, void *, bool *); - -#endif /* !_XBPS_REPO_UTIL_H_ */