From 3a52668aed04a12e97a94fbd69dae8febeb3689f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 5 Feb 2009 16:53:49 +0100 Subject: [PATCH] Reorganize headers and move two funcs into util.c, where they belong. --HG-- extra : convert_revision : 63d54dddfeb732da2204244fd9f00cff434e5540 --- include/cmpver.h | 33 +++++++++++++++++++ include/install.h | 38 ++++++++++++++++++++++ include/plist.h | 22 ------------- include/remove.h | 32 +++++++++++++++++++ include/repository.h | 42 +++++++++++++++++++++++++ include/util.h | 38 ++++++++++++++++++++++ include/xbps_api.h | 15 ++++++--- lib/depends.c | 53 +------------------------------ lib/remove.c | 24 +------------- lib/util.c | 75 +++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 269 insertions(+), 103 deletions(-) create mode 100644 include/cmpver.h create mode 100644 include/install.h create mode 100644 include/remove.h create mode 100644 include/repository.h create mode 100644 include/util.h diff --git a/include/cmpver.h b/include/cmpver.h new file mode 100644 index 0000000000..5518d7cc3a --- /dev/null +++ b/include/cmpver.h @@ -0,0 +1,33 @@ +/*- + * 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_CMPVER_H_ +#define _XBPS_CMPVER_H_ + +/* from lib/cmpver.c */ +int xbps_cmpver_packages(const char *, const char *); +int xbps_cmpver_versions(const char *, const char *); + +#endif /* !_XBPS_PLIST_H_ */ diff --git a/include/install.h b/include/install.h new file mode 100644 index 0000000000..21ef5ded05 --- /dev/null +++ b/include/install.h @@ -0,0 +1,38 @@ +/*- + * 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_INSTALL_H_ +#define _XBPS_INSTALL_H_ + +/* From lib/install.c and lib/depends.c */ +int xbps_install_pkg_deps(prop_dictionary_t); +int xbps_install_binary_pkg(const char *, const char *); +int xbps_install_binary_pkg_from_repolist(prop_object_t, void *, bool *); +int xbps_register_pkg(const char *, const char *, const char *); +int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t, + int (*cb)(struct archive *, prop_dictionary_t)); +int xbps_unpack_archive_cb(struct archive *, prop_dictionary_t); + +#endif /* !_XBPS_INSTALL_H_ */ diff --git a/include/plist.h b/include/plist.h index da2b421b6f..ae750d16b0 100644 --- a/include/plist.h +++ b/include/plist.h @@ -85,17 +85,6 @@ xbps_find_string_in_array(prop_array_t, const char *); prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t, const char *); -/* - * (Un)registers a repository specified by an URI from/into the pool. - * - * Arguments: - * - const char *: URI to (un)register. - * - * Returns true on success, or false and an appropiate errno value otherwise. - */ -bool xbps_register_repository(const char *); -bool xbps_unregister_repository(const char *); - /* * Remove package's dictionary from the "packages" array in * the specified plist file. @@ -110,23 +99,12 @@ bool xbps_remove_pkg_dict_from_file(const char *, const char *); /* Utils */ -int xbps_remove_string_from_array(prop_object_t, void *, bool *); -void xbps_set_rootdir(const char *); -char * xbps_append_full_path(bool, const char *, const char *); -int xbps_check_is_installed_pkg(const char *); -int xbps_cmpver_packages(const char *, const char *); -int xbps_cmpver_versions(const char *, const char *); -const char * xbps_get_pkg_version(const char *); -char * xbps_get_pkg_name(const char *); int xbps_install_pkg_deps(prop_dictionary_t); int xbps_install_binary_pkg(const char *, const char *); int xbps_install_binary_pkg_from_repolist(prop_object_t, void *, bool *); -int xbps_remove_binary_pkg(const char *, const char *); int xbps_register_pkg(const char *, const char *, const char *); -int xbps_unregister_pkg(const char *); int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t, int (*cb)(struct archive *, prop_dictionary_t)); int xbps_unpack_archive_cb(struct archive *, prop_dictionary_t); -bool xbps_pkg_has_rundeps(prop_dictionary_t); #endif /* !_XBPS_PLIST_H_ */ diff --git a/include/remove.h b/include/remove.h new file mode 100644 index 0000000000..45f521b8f8 --- /dev/null +++ b/include/remove.h @@ -0,0 +1,32 @@ +/*- + * 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_REMOVE_H_ +#define _XBPS_REMOVE_H_ + +int xbps_remove_binary_pkg(const char *, const char *); +int xbps_unregister_pkg(const char *); + +#endif /* !_XBPS_REMOVE_H_ */ diff --git a/include/repository.h b/include/repository.h new file mode 100644 index 0000000000..cf004016a4 --- /dev/null +++ b/include/repository.h @@ -0,0 +1,42 @@ +/*- + * 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_REPOSITORY_H_ +#define _XBPS_REPOSITORY_H_ + +/* + * (Un)registers a repository specified by an URI from/into the pool. + * + * Arguments: + * - const char *: URI to (un)register. + * + * Returns true on success, or false and an appropiate errno value otherwise. + */ +bool xbps_register_repository(const char *); +bool xbps_unregister_repository(const char *); + +int xbps_remove_string_from_array(prop_object_t, void *, bool *); + +#endif /* !_XBPS_REPOSITORY_H_ */ diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000000..d5ae883010 --- /dev/null +++ b/include/util.h @@ -0,0 +1,38 @@ +/*- + * 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_UTIL_H_ +#define _XBPS_UTIL_H_ + +/* from lib/util.c */ +char * xbps_append_full_path(bool, const char *, const char *); +int xbps_check_is_installed_pkg(const char *); +bool xbps_check_is_installed_pkgname(const char *); +const char * xbps_get_pkg_version(const char *); +char * xbps_get_pkg_name(const char *); +bool xbps_pkg_has_rundeps(prop_dictionary_t); +void xbps_set_rootdir(const char *); + +#endif /* !_XBPS_UTIL_H_ */ diff --git a/include/xbps_api.h b/include/xbps_api.h index ccec5c1376..861135bdb5 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008 Juan Romero Pardines. + * Copyright (c) 2008-2009 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,10 +54,15 @@ #define XBPS_PKG_ECHDIRDEST 4 /* chdir() to dest failed */ #define XBPS_PKG_EEMPTY 5 /* empty pkg list */ -#include "humanize_number.h" -#include "plist.h" -#include "sha256.h" -#include "queue.h" +#include "cmpver.h" #include "fexec.h" +#include "humanize_number.h" +#include "install.h" +#include "plist.h" +#include "remove.h" +#include "repository.h" +#include "sha256.h" +#include "util.h" +#include "queue.h" #endif /* !_XBPS_API_H_ */ diff --git a/lib/depends.c b/lib/depends.c index 296967717f..1f6f9e7be6 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008 Juan Romero Pardines. + * Copyright (c) 2008-2009 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,57 +46,6 @@ static SIMPLEQ_HEAD(, pkg_dependency) pkg_deps = static void xbps_destroy_dependency(struct pkg_dependency *); -int -xbps_check_is_installed_pkg(const char *pkg) -{ - prop_dictionary_t dict, pkgdict; - prop_object_t obj; - const char *reqver, *instver; - char *plist, *pkgname; - int rv = 0; - - assert(pkg != NULL); - - plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); - if (plist == NULL) - return EINVAL; - - pkgname = xbps_get_pkg_name(pkg); - reqver = xbps_get_pkg_version(pkg); - - /* Get package dictionary from plist */ - dict = prop_dictionary_internalize_from_file(plist); - if (dict == NULL) { - free(pkgname); - free(plist); - return 1; /* not installed */ - } - - pkgdict = xbps_find_pkg_in_dict(dict, pkgname); - if (pkgdict == NULL) { - prop_object_release(dict); - free(pkgname); - free(plist); - return 1; /* not installed */ - } - - /* Get version from installed package */ - obj = prop_dictionary_get(pkgdict, "version"); - assert(obj != NULL); - assert(prop_object_type(obj) == PROP_TYPE_STRING); - instver = prop_string_cstring_nocopy(obj); - assert(instver != NULL); - - /* Compare installed and required version. */ - rv = xbps_cmpver_versions(instver, reqver) > 0 ? 1 : 0; - - free(pkgname); - free(plist); - prop_object_release(dict); - - return rv; -} - void xbps_clean_pkg_depslist(void) { diff --git a/lib/remove.c b/lib/remove.c index 154cceab53..0016f490f0 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -36,28 +36,6 @@ #include -static bool -check_installed_pkgname(const char *pkgname) -{ - prop_dictionary_t pkgd; - char *plist; - - assert(pkgname != NULL); - - plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); - if (plist == NULL) - return false; - - pkgd = xbps_find_pkg_from_plist(plist, pkgname); - free(plist); - if (pkgd) { - prop_object_release(pkgd); - return true; - } - - return false; -} - int xbps_unregister_pkg(const char *pkgname) { @@ -136,7 +114,7 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir) destdir = ""; /* Check if pkg is installed */ - if (check_installed_pkgname(pkgname) == false) + if (xbps_check_is_installed_pkgname(pkgname) == false) return ENOENT; /* diff --git a/lib/util.c b/lib/util.c index 7d6bc1af29..7a8f5fca00 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008 Juan Romero Pardines. + * Copyright (c) 2008-2009 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,79 @@ static const char *rootdir; +int +xbps_check_is_installed_pkg(const char *pkg) +{ + prop_dictionary_t dict, pkgdict; + prop_object_t obj; + const char *reqver, *instver; + char *plist, *pkgname; + int rv = 0; + + assert(pkg != NULL); + + plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); + if (plist == NULL) + return EINVAL; + + pkgname = xbps_get_pkg_name(pkg); + reqver = xbps_get_pkg_version(pkg); + + /* Get package dictionary from plist */ + dict = prop_dictionary_internalize_from_file(plist); + if (dict == NULL) { + free(pkgname); + free(plist); + return 1; /* not installed */ + } + + pkgdict = xbps_find_pkg_in_dict(dict, pkgname); + if (pkgdict == NULL) { + prop_object_release(dict); + free(pkgname); + free(plist); + return 1; /* not installed */ + } + + /* Get version from installed package */ + obj = prop_dictionary_get(pkgdict, "version"); + assert(obj != NULL); + assert(prop_object_type(obj) == PROP_TYPE_STRING); + instver = prop_string_cstring_nocopy(obj); + assert(instver != NULL); + + /* Compare installed and required version. */ + rv = xbps_cmpver_versions(instver, reqver) > 0 ? 1 : 0; + + free(pkgname); + free(plist); + prop_object_release(dict); + + return rv; +} + +bool +xbps_check_is_installed_pkgname(const char *pkgname) +{ + prop_dictionary_t pkgd; + char *plist; + + assert(pkgname != NULL); + + plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); + if (plist == NULL) + return false; + + pkgd = xbps_find_pkg_from_plist(plist, pkgname); + free(plist); + if (pkgd) { + prop_object_release(pkgd); + return true; + } + + return false; +} + const char * xbps_get_pkg_version(const char *pkg) {