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
This commit is contained in:
Juan RP 2009-11-24 11:05:39 +00:00
parent 164c661bcf
commit 3a65c45de3
11 changed files with 154 additions and 148 deletions

View File

@ -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

View File

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

View File

@ -32,7 +32,7 @@
#include <xbps_api.h>
#include "defs.h"
#include "../xbps-repo/util.h"
#include "../xbps-repo/defs.h"
static void cleanup(int);
static void usage(void);

View File

@ -31,7 +31,7 @@
#include <xbps_api.h>
#include "defs.h"
#include "../xbps-repo/util.h"
#include "../xbps-repo/defs.h"
int
xbps_autoremove_pkgs(void)

View File

@ -30,8 +30,8 @@
#include <errno.h>
#include <xbps_api.h>
#include "../xbps-repo/util.h"
#include "defs.h"
#include "../xbps-repo/defs.h"
int
xbps_show_pkg_deps(const char *pkgname)

View File

@ -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 <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fnmatch.h>
#include <xbps_api.h>
#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;
}

View File

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

View File

@ -33,7 +33,7 @@
#include <sys/stat.h>
#include <xbps_api.h>
#include "index.h"
#include "defs.h"
/* Array of valid architectures */
static const char *archdirs[] = { "i686", "x86_64", "noarch", NULL };

View File

@ -32,8 +32,7 @@
#include <libgen.h>
#include <xbps_api.h>
#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);

View File

@ -31,7 +31,7 @@
#include <fnmatch.h>
#include <xbps_api.h>
#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)
{

View File

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