Reorganize headers and move two funcs into util.c, where they belong.

--HG--
extra : convert_revision : 63d54dddfeb732da2204244fd9f00cff434e5540
This commit is contained in:
Juan RP 2009-02-05 16:53:49 +01:00
parent d7b5f20e26
commit 3a52668aed
10 changed files with 269 additions and 103 deletions

33
include/cmpver.h Normal file
View file

@ -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_ */

38
include/install.h Normal file
View file

@ -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_ */

View file

@ -85,17 +85,6 @@ xbps_find_string_in_array(prop_array_t, const char *);
prop_object_iterator_t prop_object_iterator_t
xbps_get_array_iter_from_dict(prop_dictionary_t, const char *); 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 * Remove package's dictionary from the "packages" array in
* the specified plist file. * the specified plist file.
@ -110,23 +99,12 @@ bool
xbps_remove_pkg_dict_from_file(const char *, const char *); xbps_remove_pkg_dict_from_file(const char *, const char *);
/* Utils */ /* 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_pkg_deps(prop_dictionary_t);
int xbps_install_binary_pkg(const char *, const char *); int xbps_install_binary_pkg(const char *, const char *);
int xbps_install_binary_pkg_from_repolist(prop_object_t, void *, bool *); 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_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 xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t,
int (*cb)(struct archive *, prop_dictionary_t)); int (*cb)(struct archive *, prop_dictionary_t));
int xbps_unpack_archive_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_ */ #endif /* !_XBPS_PLIST_H_ */

32
include/remove.h Normal file
View file

@ -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_ */

42
include/repository.h Normal file
View file

@ -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_ */

38
include/util.h Normal file
View file

@ -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_ */

View file

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2008 Juan Romero Pardines. * Copyright (c) 2008-2009 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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_ECHDIRDEST 4 /* chdir() to dest failed */
#define XBPS_PKG_EEMPTY 5 /* empty pkg list */ #define XBPS_PKG_EEMPTY 5 /* empty pkg list */
#include "humanize_number.h" #include "cmpver.h"
#include "plist.h"
#include "sha256.h"
#include "queue.h"
#include "fexec.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_ */ #endif /* !_XBPS_API_H_ */

View file

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2008 Juan Romero Pardines. * Copyright (c) 2008-2009 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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 *); 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 void
xbps_clean_pkg_depslist(void) xbps_clean_pkg_depslist(void)
{ {

View file

@ -36,28 +36,6 @@
#include <xbps_api.h> #include <xbps_api.h>
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 int
xbps_unregister_pkg(const char *pkgname) xbps_unregister_pkg(const char *pkgname)
{ {
@ -136,7 +114,7 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
destdir = ""; destdir = "";
/* Check if pkg is installed */ /* Check if pkg is installed */
if (check_installed_pkgname(pkgname) == false) if (xbps_check_is_installed_pkgname(pkgname) == false)
return ENOENT; return ENOENT;
/* /*

View file

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2008 Juan Romero Pardines. * Copyright (c) 2008-2009 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -34,6 +34,79 @@
static const char *rootdir; 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 * const char *
xbps_get_pkg_version(const char *pkg) xbps_get_pkg_version(const char *pkg)
{ {