libxbps: unpack: simplify file hash matching code.
This commit is contained in:
parent
7909f597cb
commit
bdeeaa46b8
@ -31,45 +31,29 @@
|
|||||||
#include "xbps_api_impl.h"
|
#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
|
int HIDDEN
|
||||||
xbps_entry_is_a_conf_file(prop_dictionary_t propsd,
|
xbps_entry_is_a_conf_file(prop_dictionary_t propsd,
|
||||||
const char *entry_pname)
|
const char *entry_pname)
|
||||||
{
|
{
|
||||||
prop_object_t obj;
|
prop_array_t array;
|
||||||
prop_object_iterator_t iter;
|
const char *cffile;
|
||||||
char *cffile;
|
size_t i;
|
||||||
int rv = 0;
|
|
||||||
|
|
||||||
assert(prop_object_type(propsd) == PROP_TYPE_DICTIONARY);
|
assert(prop_object_type(propsd) == PROP_TYPE_DICTIONARY);
|
||||||
assert(entry_pname != NULL);
|
assert(entry_pname != NULL);
|
||||||
|
|
||||||
if (!prop_dictionary_get(propsd, "conf_files"))
|
array = prop_dictionary_get(propsd, "conf_files");
|
||||||
return 0;
|
if (array == NULL || prop_array_count(array) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
iter = xbps_array_iter_from_dict(propsd, "conf_files");
|
for (i = 0; i < prop_array_count(array); i++) {
|
||||||
if (iter == NULL)
|
prop_array_get_cstring_nocopy(array, i, &cffile);
|
||||||
return -1;
|
if (strcmp(cffile, entry_pname) == 0)
|
||||||
|
return true;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
out:
|
|
||||||
prop_object_iterator_release(iter);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -358,12 +358,11 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
*/
|
*/
|
||||||
conf_file = file_exists = false;
|
conf_file = file_exists = false;
|
||||||
if (S_ISREG(entry_statp->st_mode)) {
|
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;
|
conf_file = true;
|
||||||
if (stat(entry_pname, &st) == 0) {
|
if (stat(entry_pname, &st) == 0) {
|
||||||
/* remove first char, i.e '.' */
|
|
||||||
buf = strchr(entry_pname, '.') + 1;
|
|
||||||
assert(buf != NULL);
|
|
||||||
file_exists = true;
|
file_exists = true;
|
||||||
rv = xbps_file_hash_check_dictionary(xhp, filesd,
|
rv = xbps_file_hash_check_dictionary(xhp, filesd,
|
||||||
conf_file ? "conf_files" : "files", buf);
|
conf_file ? "conf_files" : "files", buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user