From bdeeaa46b801e786f9824948b5aefc3c3ae97571 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 30 Sep 2012 17:07:51 +0200 Subject: [PATCH] libxbps: unpack: simplify file hash matching code. --- lib/package_config_files.c | 40 ++++++++++++-------------------------- lib/package_unpack.c | 7 +++---- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/lib/package_config_files.c b/lib/package_config_files.c index 690bd09e..b8c64aea 100644 --- a/lib/package_config_files.c +++ b/lib/package_config_files.c @@ -31,45 +31,29 @@ #include "xbps_api_impl.h" /* - * Returns 1 if entry is a configuration file, 0 if don't or -1 on error. + * Returns true if entry is a configuration file, false otherwise. */ int HIDDEN xbps_entry_is_a_conf_file(prop_dictionary_t propsd, const char *entry_pname) { - prop_object_t obj; - prop_object_iterator_t iter; - char *cffile; - int rv = 0; + prop_array_t array; + const char *cffile; + size_t i; assert(prop_object_type(propsd) == PROP_TYPE_DICTIONARY); assert(entry_pname != NULL); - if (!prop_dictionary_get(propsd, "conf_files")) - return 0; + array = prop_dictionary_get(propsd, "conf_files"); + if (array == NULL || prop_array_count(array) == 0) + return false; - iter = xbps_array_iter_from_dict(propsd, "conf_files"); - if (iter == NULL) - return -1; - - while ((obj = prop_object_iterator_next(iter))) { - cffile = xbps_xasprintf(".%s", - prop_string_cstring_nocopy(obj)); - if (cffile == NULL) { - rv = -1; - goto out; - } - if (strcmp(cffile, entry_pname) == 0) { - rv = 1; - free(cffile); - break; - } - free(cffile); + for (i = 0; i < prop_array_count(array); i++) { + prop_array_get_cstring_nocopy(array, i, &cffile); + if (strcmp(cffile, entry_pname) == 0) + return true; } - -out: - prop_object_iterator_release(iter); - return rv; + return false; } /* diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 903ff53e..24b3548a 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -358,12 +358,11 @@ unpack_archive(struct xbps_handle *xhp, */ conf_file = file_exists = false; if (S_ISREG(entry_statp->st_mode)) { - if (xbps_entry_is_a_conf_file(propsd, entry_pname)) + buf = strchr(entry_pname, '.') + 1; + assert(buf != NULL); + if (xbps_entry_is_a_conf_file(propsd, buf)) conf_file = true; if (stat(entry_pname, &st) == 0) { - /* remove first char, i.e '.' */ - buf = strchr(entry_pname, '.') + 1; - assert(buf != NULL); file_exists = true; rv = xbps_file_hash_check_dictionary(xhp, filesd, conf_file ? "conf_files" : "files", buf);