From cf2015f6922a7613bfd3992e77aa9a0f224b28d5 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 30 Oct 2008 08:47:00 +0100 Subject: [PATCH] xbps-pkgdb: add function to internalize plist file. --HG-- extra : convert_revision : 0a303377d6c17b80eb9ff36b0309247a624c3e3e --- utils/xbps-pkgdb.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/utils/xbps-pkgdb.c b/utils/xbps-pkgdb.c index 396566d5bf..3a36ee2f19 100644 --- a/utils/xbps-pkgdb.c +++ b/utils/xbps-pkgdb.c @@ -49,6 +49,7 @@ static void register_pkg(prop_dictionary_t, pkg_data_t *, const char *); static void unregister_pkg(prop_dictionary_t, const char *, const char *); static void write_plist_file(prop_dictionary_t, const char *); static void list_pkgs_in_dict(prop_dictionary_t); +static prop_dictionary_t get_dict_from_dbfile(const char *); static void usage(void) @@ -277,6 +278,19 @@ list_pkgs_in_dict(prop_dictionary_t dict) prop_object_iterator_release(iter); } +static prop_dictionary_t +get_dict_from_dbfile(const char *file) +{ + prop_dictionary_t dict; + + dict = prop_dictionary_internalize_from_file(file); + if (dict == NULL) { + perror("=> ERROR: couldn't find database file"); + exit(1); + } + return dict; +} + int main(int argc, char **argv) { @@ -364,13 +378,7 @@ main(int argc, char **argv) if (argc != 4) usage(); - dbdict = prop_dictionary_internalize_from_file(dbfile); - if (dbdict == NULL) { - perror("=> ERROR: couldn't read database file"); - exit(1); - } - - unregister_pkg(dbdict, argv[2], dbfile); + unregister_pkg(get_dict_from_dbfile(dbfile), argv[2], dbfile); printf("%s=> %s-%s unregistered successfully.\n", in_chroot ? "[chroot] " : "", argv[2], argv[3]); @@ -380,25 +388,14 @@ main(int argc, char **argv) if (argc != 2) usage(); - dbdict = prop_dictionary_internalize_from_file(dbfile); - if (dbdict == NULL) { - perror("=> ERROR: couldn't read database file"); - exit(1); - } - - list_pkgs_in_dict(dbdict); + list_pkgs_in_dict(get_dict_from_dbfile(dbfile)); } else if (strcmp(argv[1], "version") == 0) { /* Prints version of an installed package */ if (argc != 3) usage(); - dbdict = prop_dictionary_internalize_from_file(dbfile); - if (dbdict == NULL) { - perror("=> ERROR: couldn't read database file"); - exit(1); - } - pkgdict = find_pkg_in_dict(dbdict, argv[2]); + pkgdict = find_pkg_in_dict(get_dict_from_dbfile(dbfile), argv[2]); if (pkgdict == NULL) exit(1); if (!prop_dictionary_get_cstring_nocopy(pkgdict, "version", &version))