libxbps: performance improvements by caching the most accessed paths.

1- We can cache the result of the first xbps_pkgdb_init() when it fails
   and avoid the malloc/free/access from it.
2- We cache the uname(2) result into a private var in xbps_handle and
   use it in xbps_pkg_arch_match().

This improves performance by ~5% approx and it's close as it was before
introducing the repository index format 1.5.
This commit is contained in:
Juan RP 2012-06-15 15:33:11 +02:00
parent 506625a716
commit 068cab8d20
22 changed files with 272 additions and 159 deletions

View File

@ -168,7 +168,7 @@ remove_stale_entries_in_reqby(struct xbps_handle *xhp,
} }
printf("%s: found stale entry in requiredby `%s' (fixed)\n", printf("%s: found stale entry in requiredby `%s' (fixed)\n",
crd->pkgver, str); crd->pkgver, str);
if (xbps_remove_string_from_array(crd->pkgd_reqby, str)) if (xbps_remove_string_from_array(xhp, crd->pkgd_reqby, str))
needs_update = true; needs_update = true;
} }
if (needs_update) { if (needs_update) {

View File

@ -49,7 +49,7 @@ list_pkgs_in_dict(struct xbps_handle *xhp,
(void)loop_done; (void)loop_done;
chkarch = prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); chkarch = prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (chkarch && !xbps_pkg_arch_match(arch, NULL)) if (chkarch && !xbps_pkg_arch_match(xhp, arch, NULL))
return 0; return 0;
if (lpc->check_state) { if (lpc->check_state) {

View File

@ -39,7 +39,9 @@ struct ffdata {
}; };
static void static void
match_files_by_pattern(prop_dictionary_t pkg_filesd, struct ffdata *ffd) match_files_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t pkg_filesd,
struct ffdata *ffd)
{ {
prop_array_t array; prop_array_t array;
const char *filestr, *pkgver, *arch; const char *filestr, *pkgver, *arch;
@ -47,7 +49,7 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, struct ffdata *ffd)
int x; int x;
prop_dictionary_get_cstring_nocopy(pkg_filesd, "architecture", &arch); prop_dictionary_get_cstring_nocopy(pkg_filesd, "architecture", &arch);
if (!xbps_pkg_arch_match(arch, NULL)) if (!xbps_pkg_arch_match(xhp, arch, NULL))
return; return;
array = prop_dictionary_get(pkg_filesd, "files"); array = prop_dictionary_get(pkg_filesd, "files");
@ -94,7 +96,7 @@ find_files_in_package(struct xbps_handle *xhp,
ffd->repouri = rpi->uri; ffd->repouri = rpi->uri;
for (i = 0; i < prop_array_count(idxfiles); i++) for (i = 0; i < prop_array_count(idxfiles); i++)
match_files_by_pattern(prop_array_get(idxfiles, i), ffd); match_files_by_pattern(xhp, prop_array_get(idxfiles, i), ffd);
prop_object_release(idxfiles); prop_object_release(idxfiles);
return 0; return 0;

View File

@ -56,7 +56,7 @@ rmobsoletes_files_cb(struct xbps_handle *xhp,
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (xbps_find_pkg_in_array_by_pkgver(ifd->idx, pkgver, arch)) { if (xbps_find_pkg_in_array_by_pkgver(xhp, ifd->idx, pkgver, arch)) {
/* pkg found, do nothing */ /* pkg found, do nothing */
return 0; return 0;
} }
@ -95,7 +95,7 @@ genindex_files_cb(struct xbps_handle *xhp,
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (xbps_find_pkg_in_array_by_pkgver(ifd->idxfiles, pkgver, arch)) { if (xbps_find_pkg_in_array_by_pkgver(xhp, ifd->idxfiles, pkgver, arch)) {
fprintf(stderr, "index-files: skipping `%s' (%s), " fprintf(stderr, "index-files: skipping `%s' (%s), "
"already registered.\n", pkgver, arch); "already registered.\n", pkgver, arch);
return 0; return 0;
@ -278,7 +278,7 @@ repo_genindex_files(struct xbps_handle *xhp, const char *pkgdir)
} }
arch = strchr(p, ',') + 1; arch = strchr(p, ',') + 1;
if (!xbps_remove_pkg_from_array_by_pkgver( if (!xbps_remove_pkg_from_array_by_pkgver(
ifd->idxfiles, pkgver, arch)) { xhp, ifd->idxfiles, pkgver, arch)) {
free(pkgver); free(pkgver);
rv = EINVAL; rv = EINVAL;
goto out; goto out;

View File

@ -129,7 +129,8 @@ repoidx_get(struct xbps_handle *xhp, const char *pkgdir)
} }
static int static int
add_binpkg_to_index(prop_array_t idx, add_binpkg_to_index(struct xbps_handle *xhp,
prop_array_t idx,
const char *filedir, const char *filedir,
const char *file) const char *file)
{ {
@ -165,7 +166,7 @@ add_binpkg_to_index(prop_array_t idx,
* than current registered package, update the index; otherwise * than current registered package, update the index; otherwise
* pass to the next one. * pass to the next one.
*/ */
curpkgd = xbps_find_pkg_in_array_by_name(idx, pkgname, arch); curpkgd = xbps_find_pkg_in_array_by_name(xhp, idx, pkgname, arch);
if (curpkgd == NULL) { if (curpkgd == NULL) {
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
prop_object_release(newpkgd); prop_object_release(newpkgd);
@ -236,7 +237,8 @@ add_binpkg_to_index(prop_array_t idx,
goto out; goto out;
} }
free(oldfilepath); free(oldfilepath);
if (!xbps_remove_pkg_from_array_by_pkgver(idx, buf, oldarch)) { if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
buf, oldarch)) {
xbps_error_printf("failed to remove `%s' " xbps_error_printf("failed to remove `%s' "
"from plist index: %s\n", buf, strerror(errno)); "from plist index: %s\n", buf, strerror(errno));
prop_object_release(newpkgd); prop_object_release(newpkgd);
@ -350,7 +352,7 @@ repo_genindex(struct xbps_handle *xhp, const char *pkgdir)
rv = errno; rv = errno;
goto out; goto out;
} }
rv = add_binpkg_to_index(idx, curdir, binfile); rv = add_binpkg_to_index(xhp, idx, curdir, binfile);
free(binfile); free(binfile);
if (rv == EEXIST) { if (rv == EEXIST) {
rv = 0; rv = 0;

View File

@ -108,7 +108,7 @@ show_pkg_namedesc(struct xbps_handle *xhp,
(void)loop_done; (void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (!xbps_pkg_arch_match(arch, NULL)) if (!xbps_pkg_arch_match(xhp, arch, NULL))
return 0; return 0;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120614-2" #define XBPS_API_VERSION "20120615"
#define XBPS_VERSION "0.16" #define XBPS_VERSION "0.16"
/** /**
@ -527,6 +527,7 @@ struct xbps_handle {
*/ */
char *cachedir_priv; char *cachedir_priv;
char *metadir_priv; char *metadir_priv;
char *un_machine;
/** /**
* @var conffile * @var conffile
* *
@ -901,6 +902,7 @@ int xbps_callback_array_iter_reverse_in_dict(struct xbps_handle *xhp,
* Finds the proplib's dictionary associated with a package, by looking * Finds the proplib's dictionary associated with a package, by looking
* it via its name in a proplib dictionary. * it via its name in a proplib dictionary.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] dict Proplib dictionary to look for the package dictionary. * @param[in] dict Proplib dictionary to look for the package dictionary.
* @param[in] key Key associated with the array that stores package's dictionary. * @param[in] key Key associated with the array that stores package's dictionary.
* @param[in] pkgname Package name to look for. * @param[in] pkgname Package name to look for.
@ -908,7 +910,8 @@ int xbps_callback_array_iter_reverse_in_dict(struct xbps_handle *xhp,
* @return The package's proplib dictionary on success, NULL otherwise and * @return The package's proplib dictionary on success, NULL otherwise and
* errno is set appropiately. * errno is set appropiately.
*/ */
prop_dictionary_t xbps_find_pkg_in_dict_by_name(prop_dictionary_t dict, prop_dictionary_t xbps_find_pkg_in_dict_by_name(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
const char *pkgname); const char *pkgname);
@ -916,6 +919,7 @@ prop_dictionary_t xbps_find_pkg_in_dict_by_name(prop_dictionary_t dict,
* Finds the proplib's dictionary associated with a package, by looking * Finds the proplib's dictionary associated with a package, by looking
* at it via a package pattern in a proplib dictionary. * at it via a package pattern in a proplib dictionary.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] dict Proplib dictionary to look for the package dictionary. * @param[in] dict Proplib dictionary to look for the package dictionary.
* @param[in] key Key associated with the array storing the package's dictionary. * @param[in] key Key associated with the array storing the package's dictionary.
* @param[in] pattern Package pattern to match. * @param[in] pattern Package pattern to match.
@ -923,7 +927,8 @@ prop_dictionary_t xbps_find_pkg_in_dict_by_name(prop_dictionary_t dict,
* @return The package's proplib dictionary on success, NULL otherwise * @return The package's proplib dictionary on success, NULL otherwise
* and errno is set appropiately. * and errno is set appropiately.
*/ */
prop_dictionary_t xbps_find_pkg_in_dict_by_pattern(prop_dictionary_t dict, prop_dictionary_t xbps_find_pkg_in_dict_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
const char *pattern); const char *pattern);
@ -931,15 +936,17 @@ prop_dictionary_t xbps_find_pkg_in_dict_by_pattern(prop_dictionary_t dict,
* Finds the proplib's dictionary associated with a package, by matching * Finds the proplib's dictionary associated with a package, by matching
* its \a pkgver object in its dictionary. * its \a pkgver object in its dictionary.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] dict Proplib dictionary to look for the package dictionary. * @param[in] dict Proplib dictionary to look for the package dictionary.
* @param[in] key Key associated with the array storing the package's * @param[in] key Key associated with the array storing the package's
* dictionary. * dictionary.
* @param[in] pkgver Package name/version to match, i.e `foo-1.0'. * @param[in] pkgver Package name/version to match, i.e `foo-1.0_1'.
* *
* @return The package's proplib dictionary on success, NULL otherwise * @return The package's proplib dictionary on success, NULL otherwise
* and errno is set appropiately. * and errno is set appropiately.
*/ */
prop_dictionary_t xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t dict, prop_dictionary_t xbps_find_pkg_in_dict_by_pkgver(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key, const char *key,
const char *pkgver); const char *pkgver);
@ -948,6 +955,7 @@ prop_dictionary_t xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t dict,
* a pkgname in \a name on any of the virtual package in * a pkgname in \a name on any of the virtual package in
* the "provides" array object. * the "provides" array object.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] d Proplib dictionary to look for the package dictionary. * @param[in] d Proplib dictionary to look for the package dictionary.
* @param[in] key Key associated with the array storing the package's * @param[in] key Key associated with the array storing the package's
* dictionary. * dictionary.
@ -958,7 +966,8 @@ prop_dictionary_t xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t dict,
* Finds a virtual package dictionary in a proplib array by matching a * Finds a virtual package dictionary in a proplib array by matching a
* package name. * package name.
*/ */
prop_dictionary_t xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d, prop_dictionary_t xbps_find_virtualpkg_in_dict_by_name(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *name); const char *name);
@ -967,6 +976,7 @@ prop_dictionary_t xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d,
* a pkg pattern in \a pattern on any of the virtual package in * a pkg pattern in \a pattern on any of the virtual package in
* the "provides" array object. * the "provides" array object.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] d Proplib dictionary to look for the package dictionary. * @param[in] d Proplib dictionary to look for the package dictionary.
* @param[in] key Key associated with the array storing the package's * @param[in] key Key associated with the array storing the package's
* dictionary. * dictionary.
@ -976,7 +986,8 @@ prop_dictionary_t xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d,
* @return The package dictionary, otherwise NULL is returned and errno * @return The package dictionary, otherwise NULL is returned and errno
* is set appropiately. * is set appropiately.
*/ */
prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d, prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *pattern); const char *pattern);
@ -1049,6 +1060,7 @@ bool xbps_match_any_virtualpkg_in_rundeps(prop_array_t rundeps,
/** /**
* Finds a package dictionary in a proplib array by matching a package name. * Finds a package dictionary in a proplib array by matching a package name.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array The proplib array to search on. * @param[in] array The proplib array to search on.
* @param[in] name The package name to match. * @param[in] name The package name to match.
* @param[in] targetarch If set, package will be matched against this * @param[in] targetarch If set, package will be matched against this
@ -1056,13 +1068,15 @@ bool xbps_match_any_virtualpkg_in_rundeps(prop_array_t rundeps,
* *
* @return The package dictionary, otherwise NULL is returned. * @return The package dictionary, otherwise NULL is returned.
*/ */
prop_dictionary_t xbps_find_pkg_in_array_by_name(prop_array_t array, prop_dictionary_t xbps_find_pkg_in_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name, const char *name,
const char *targetarch); const char *targetarch);
/** /**
* Finds a package dictionary in a proplib array by matching a package pattern. * Finds a package dictionary in a proplib array by matching a package pattern.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array The proplib array to search on. * @param[in] array The proplib array to search on.
* @param[in] pattern The package pattern to match, i.e `foo>=0' or `foo<1'. * @param[in] pattern The package pattern to match, i.e `foo>=0' or `foo<1'.
* @param[in] targetarch If set, package will be matched against this * @param[in] targetarch If set, package will be matched against this
@ -1070,7 +1084,8 @@ prop_dictionary_t xbps_find_pkg_in_array_by_name(prop_array_t array,
* *
* @return The package dictionary, otherwise NULL is returned. * @return The package dictionary, otherwise NULL is returned.
*/ */
prop_dictionary_t xbps_find_pkg_in_array_by_pattern(prop_array_t array, prop_dictionary_t xbps_find_pkg_in_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *pattern, const char *pattern,
const char *targetarch); const char *targetarch);
@ -1078,6 +1093,7 @@ prop_dictionary_t xbps_find_pkg_in_array_by_pattern(prop_array_t array,
* Finds a package dictionary in a proplib array by matching a \a pkgver * Finds a package dictionary in a proplib array by matching a \a pkgver
* object. * object.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array The proplib array to search on. * @param[in] array The proplib array to search on.
* @param[in] pkgver The package name/version to match, i.e `foo-1.0'. * @param[in] pkgver The package name/version to match, i.e `foo-1.0'.
* @param[in] targetarch If set, package will be matched against this * @param[in] targetarch If set, package will be matched against this
@ -1085,7 +1101,8 @@ prop_dictionary_t xbps_find_pkg_in_array_by_pattern(prop_array_t array,
* *
* @return The package dictionary, otherwise NULL is returned. * @return The package dictionary, otherwise NULL is returned.
*/ */
prop_dictionary_t xbps_find_pkg_in_array_by_pkgver(prop_array_t array, prop_dictionary_t xbps_find_pkg_in_array_by_pkgver(struct xbps_handle *xhp,
prop_array_t array,
const char *pkgver, const char *pkgver,
const char *targetarch); const char *targetarch);
@ -1093,25 +1110,30 @@ prop_dictionary_t xbps_find_pkg_in_array_by_pkgver(prop_array_t array,
* Finds a virtual package dictionary in a proplib array by matching a * Finds a virtual package dictionary in a proplib array by matching a
* package name. * package name.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array The proplib array to search on. * @param[in] array The proplib array to search on.
* @param[in] name The virtual package name to match. * @param[in] name The virtual package name to match.
* *
* @return The package dictionary, otherwise NULL is returned. * @return The package dictionary, otherwise NULL is returned.
*/ */
prop_dictionary_t xbps_find_virtualpkg_in_array_by_name(prop_array_t array, prop_dictionary_t xbps_find_virtualpkg_in_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name); const char *name);
/** /**
* Finds a virtual package dictionary in a proplib array by matching a * Finds a virtual package dictionary in a proplib array by matching a
* package pattern. * package pattern.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array The proplib array to search on. * @param[in] array The proplib array to search on.
* @param[in] pattern The virtual package pattern to match, i.e * @param[in] pattern The virtual package pattern to match, i.e
* `foo>=0' or `foo<1'. * `foo>=0' or `foo<1'.
* *
* @return The package dictionary, otherwise NULL is returned. * @return The package dictionary, otherwise NULL is returned.
*/ */
prop_dictionary_t xbps_find_virtualpkg_in_array_by_pattern(prop_array_t array, prop_dictionary_t
xbps_find_virtualpkg_in_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *pattern); const char *pattern);
/** /**
@ -1187,6 +1209,7 @@ prop_dictionary_t xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
* Removes the package's proplib dictionary matching \a pkgname * Removes the package's proplib dictionary matching \a pkgname
* in a proplib array. * in a proplib array.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array Proplib array where to look for. * @param[in] array Proplib array where to look for.
* @param[in] name Package name to match in the array. * @param[in] name Package name to match in the array.
* @param[in] targetarch If set, package will be matched against this * @param[in] targetarch If set, package will be matched against this
@ -1194,7 +1217,8 @@ prop_dictionary_t xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
* *
* @return true on success, false otherwise and errno is set appropiately. * @return true on success, false otherwise and errno is set appropiately.
*/ */
bool xbps_remove_pkg_from_array_by_name(prop_array_t array, bool xbps_remove_pkg_from_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name, const char *name,
const char *targetarch); const char *targetarch);
@ -1202,6 +1226,7 @@ bool xbps_remove_pkg_from_array_by_name(prop_array_t array,
* Removes the package's proplib dictionary matching the pkgver object * Removes the package's proplib dictionary matching the pkgver object
* with a package pattern from \a pattern in a proplib array. * with a package pattern from \a pattern in a proplib array.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array Proplib array where to look for. * @param[in] array Proplib array where to look for.
* @param[in] pattern Package pattern to match, i.e `foo>=0' or `foo<1'. * @param[in] pattern Package pattern to match, i.e `foo>=0' or `foo<1'.
* @param[in] targetarch If set, package will be matched against this * @param[in] targetarch If set, package will be matched against this
@ -1209,7 +1234,8 @@ bool xbps_remove_pkg_from_array_by_name(prop_array_t array,
* *
* @return true on success, false otherwise and errno is set appropiately. * @return true on success, false otherwise and errno is set appropiately.
*/ */
bool xbps_remove_pkg_from_array_by_pattern(prop_array_t array, bool xbps_remove_pkg_from_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *pattern, const char *pattern,
const char *targetarch); const char *targetarch);
@ -1217,6 +1243,7 @@ bool xbps_remove_pkg_from_array_by_pattern(prop_array_t array,
* Removes the package's proplib dictionary matching the \a pkgver * Removes the package's proplib dictionary matching the \a pkgver
* object in a proplib array of dictionaries. * object in a proplib array of dictionaries.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array Proplib array where to look for. * @param[in] array Proplib array where to look for.
* @param[in] pkgver Package name/version to match, i.e `foo-1.0'. * @param[in] pkgver Package name/version to match, i.e `foo-1.0'.
* @param[in] targetarch If set, package will be matched against this * @param[in] targetarch If set, package will be matched against this
@ -1224,29 +1251,36 @@ bool xbps_remove_pkg_from_array_by_pattern(prop_array_t array,
* *
* @return true on success, false otherwise and errno is set appropiately. * @return true on success, false otherwise and errno is set appropiately.
*/ */
bool xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, bool xbps_remove_pkg_from_array_by_pkgver(struct xbps_handle *xhp,
prop_array_t array,
const char *pkgver, const char *pkgver,
const char *targetarch); const char *targetarch);
/** /**
* Removes a string from a proplib's array of strings. * Removes a string from a proplib's array of strings.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array Proplib array where to look for. * @param[in] array Proplib array where to look for.
* @param[in] str String to match in the array. * @param[in] str String to match in the array.
* *
* @return true on success, false otherwise and errno is set appropiately. * @return true on success, false otherwise and errno is set appropiately.
*/ */
bool xbps_remove_string_from_array(prop_array_t array, const char *str); bool xbps_remove_string_from_array(struct xbps_handle *xhp,
prop_array_t array,
const char *str);
/** /**
* Removes a string from a proplib's array matched by a package name. * Removes a string from a proplib's array matched by a package name.
* *
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] array Proplib array where to look for. * @param[in] array Proplib array where to look for.
* @param[in] name Package name to match. * @param[in] name Package name to match.
* *
* @return true on success, false otherwise and errno is set appropiately. * @return true on success, false otherwise and errno is set appropiately.
*/ */
bool xbps_remove_pkgname_from_array(prop_array_t array, const char *name); bool xbps_remove_pkgname_from_array(struct xbps_handle *xhp,
prop_array_t array,
const char *name);
/** /**
* Replaces a dictionary with another dictionary in \a dict, in the * Replaces a dictionary with another dictionary in \a dict, in the
@ -1992,13 +2026,16 @@ bool xbps_pkg_has_rundeps(prop_dictionary_t dict);
/** /**
* Returns true if provided string is valid for target architecture. * Returns true if provided string is valid for target architecture.
* *
* @param[in] xhp The pointer to an xbps_handle struct.
* @param[in] orig Architecture to match. * @param[in] orig Architecture to match.
* @param[in] target If not NULL, \a orig will be matched against it * @param[in] target If not NULL, \a orig will be matched against it
* rather than returned value of uname(2). * rather than returned value of uname(2).
* *
* @return True on match, false otherwise. * @return True on match, false otherwise.
*/ */
bool xbps_pkg_arch_match(const char *orig, const char *target); bool xbps_pkg_arch_match(struct xbps_handle *xhp,
const char *orig,
const char *target);
/** /**
* Converts the 64 bits signed number specified in \a bytes to * Converts the 64 bits signed number specified in \a bytes to

View File

@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/utsname.h>
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
@ -114,6 +115,7 @@ xbps_init(struct xbps_handle *xhp)
CFG_FUNC(__UNCONST("include"), &cfg_include), CFG_FUNC(__UNCONST("include"), &cfg_include),
CFG_END() CFG_END()
}; };
struct utsname un;
int rv, cc, cch; int rv, cc, cch;
bool syslog_enabled = false; bool syslog_enabled = false;
@ -170,6 +172,10 @@ xbps_init(struct xbps_handle *xhp)
return ENOMEM; return ENOMEM;
xhp->metadir = xhp->metadir_priv; xhp->metadir = xhp->metadir_priv;
uname(&un);
xhp->un_machine = strdup(un.machine);
assert(xhp->un_machine);
if (xhp->cfg == NULL) { if (xhp->cfg == NULL) {
xhp->flags |= XBPS_FLAG_SYSLOG; xhp->flags |= XBPS_FLAG_SYSLOG;
xhp->fetch_timeout = XBPS_FETCH_TIMEOUT; xhp->fetch_timeout = XBPS_FETCH_TIMEOUT;
@ -199,6 +205,7 @@ xbps_init(struct xbps_handle *xhp)
xbps_dbg_printf(xhp, "Syslog=%u\n", syslog_enabled); xbps_dbg_printf(xhp, "Syslog=%u\n", syslog_enabled);
xbps_dbg_printf(xhp, "TransactionFrequencyFlush=%u\n", xbps_dbg_printf(xhp, "TransactionFrequencyFlush=%u\n",
xhp->transaction_frequency_flush); xhp->transaction_frequency_flush);
xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->un_machine);
xbps_initialized = true; xbps_initialized = true;
@ -217,10 +224,10 @@ xbps_end(struct xbps_handle *xhp)
if (xhp->cfg != NULL) if (xhp->cfg != NULL)
cfg_free(xhp->cfg); cfg_free(xhp->cfg);
if (xhp->cachedir_priv != NULL)
free(xhp->cachedir_priv); free(xhp->cachedir_priv);
if (xhp->metadir_priv != NULL)
free(xhp->metadir_priv); free(xhp->metadir_priv);
free(xhp->un_machine);
xhp = NULL; xhp = NULL;
xbps_initialized = false; xbps_initialized = false;

View File

@ -66,7 +66,7 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
/* /*
* Check if current pkg conflicts with any pkg in transaction. * Check if current pkg conflicts with any pkg in transaction.
*/ */
pkgd = xbps_find_pkg_in_dict_by_pattern(xhp->transd, pkgd = xbps_find_pkg_in_dict_by_pattern(xhp, xhp->transd,
"unsorted_deps", cfpkg); "unsorted_deps", cfpkg);
if (pkgd != NULL) { if (pkgd != NULL) {
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,

View File

@ -137,7 +137,7 @@ find_orphan_pkg(struct xbps_handle *xhp,
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
return EINVAL; return EINVAL;
} }
if (xbps_find_pkg_in_array_by_pattern(od->array, pkgdep, NULL)) if (xbps_find_pkg_in_array_by_pattern(xhp, od->array, pkgdep, NULL))
ndep++; ndep++;
if (od->orphans_user == NULL) if (od->orphans_user == NULL)
continue; continue;

View File

@ -58,7 +58,7 @@ add_pkg_into_reqby(struct xbps_handle *xhp,
return ENOMEM; return ENOMEM;
if (xbps_match_pkgname_in_array(reqby, pkgname)) { if (xbps_match_pkgname_in_array(reqby, pkgname)) {
if (!xbps_remove_pkgname_from_array(reqby, pkgname)) { if (!xbps_remove_pkgname_from_array(xhp, reqby, pkgname)) {
xbps_dbg_printf(xhp, "%s: failed to remove %s reqby entry: " xbps_dbg_printf(xhp, "%s: failed to remove %s reqby entry: "
"%s\n", __func__, pkgname, strerror(errno)); "%s\n", __func__, pkgname, strerror(errno));
free(pkgname); free(pkgname);
@ -113,7 +113,7 @@ remove_pkg_from_reqby(struct xbps_handle *xhp,
return 0; return 0;
if (xbps_match_pkgname_in_array(reqby, pkgname)) { if (xbps_match_pkgname_in_array(reqby, pkgname)) {
if (!xbps_remove_pkgname_from_array(reqby, pkgname)) if (!xbps_remove_pkgname_from_array(xhp, reqby, pkgname))
return EINVAL; return EINVAL;
} }
@ -161,10 +161,10 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
if (pkgd_pkgdb == NULL) { if (pkgd_pkgdb == NULL) {
pkgd_pkgdb = pkgd_pkgdb =
xbps_find_virtualpkg_in_array_by_pattern( xbps_find_virtualpkg_in_array_by_pattern(
xhp->pkgdb, str); xhp, xhp->pkgdb, str);
if (pkgd_pkgdb == NULL) { if (pkgd_pkgdb == NULL) {
pkgd_pkgdb = xbps_find_pkg_in_array_by_pattern( pkgd_pkgdb = xbps_find_pkg_in_array_by_pattern(
xhp->pkgdb, str, NULL); xhp, xhp->pkgdb, str, NULL);
if (pkgd_pkgdb == NULL) { if (pkgd_pkgdb == NULL) {
rv = ENOENT; rv = ENOENT;
xbps_dbg_printf(xhp, xbps_dbg_printf(xhp,

View File

@ -80,31 +80,16 @@ int
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush) xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
{ {
char *plist; char *plist;
static int cached_rv;
int rv = 0; int rv = 0;
plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB); if (cached_rv && !flush)
if (plist == NULL) return cached_rv;
return ENOMEM;
if (xhp->pkgdb != NULL && flush) { plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
/* Create metadir if doesn't exist */ assert(plist);
if (access(xhp->metadir, X_OK) == -1) {
if (errno == ENOENT) { if (xhp->pkgdb && flush) {
if (xbps_mkpath(xhp->metadir, 0755) != 0) {
xbps_dbg_printf(xhp,
"[pkgdb] failed to "
"create metadir %s: %s\n",
xhp->metadir,
strerror(errno));
rv = errno;
free(plist);
return rv;
}
} else {
free(plist);
return errno;
}
}
/* flush dictionary to storage */ /* flush dictionary to storage */
if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) { if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) {
free(plist); free(plist);
@ -112,11 +97,11 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
} }
prop_object_release(xhp->pkgdb); prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL; xhp->pkgdb = NULL;
cached_rv = 0;
} }
/* update copy in memory */ /* update copy in memory */
xhp->pkgdb = prop_array_internalize_from_zfile(plist); if ((xhp->pkgdb = prop_array_internalize_from_zfile(plist)) == NULL)
if (xhp->pkgdb == NULL) cached_rv = rv = errno;
rv = errno;
free(plist); free(plist);
@ -180,9 +165,9 @@ xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern)
return NULL; return NULL;
if (bypattern) if (bypattern)
pkgd = xbps_find_pkg_in_array_by_pattern(xhp->pkgdb, pkg, NULL); pkgd = xbps_find_pkg_in_array_by_pattern(xhp, xhp->pkgdb, pkg, NULL);
else else
pkgd = xbps_find_pkg_in_array_by_name(xhp->pkgdb, pkg, NULL); pkgd = xbps_find_pkg_in_array_by_name(xhp, xhp->pkgdb, pkg, NULL);
if (pkgd != NULL) if (pkgd != NULL)
return prop_dictionary_copy(pkgd); return prop_dictionary_copy(pkgd);
@ -198,7 +183,7 @@ xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp, const char *pkgver)
if (xbps_pkgdb_init(xhp) != 0) if (xbps_pkgdb_init(xhp) != 0)
return NULL; return NULL;
pkgd = xbps_find_pkg_in_array_by_pkgver(xhp->pkgdb, pkgver, NULL); pkgd = xbps_find_pkg_in_array_by_pkgver(xhp, xhp->pkgdb, pkgver, NULL);
if (pkgd != NULL) if (pkgd != NULL)
return prop_dictionary_copy(pkgd); return prop_dictionary_copy(pkgd);
@ -217,9 +202,11 @@ xbps_pkgdb_remove_pkgd(struct xbps_handle *xhp,
return false; return false;
if (bypattern) if (bypattern)
rv = xbps_remove_pkg_from_array_by_pattern(xhp->pkgdb, pkg, NULL); rv = xbps_remove_pkg_from_array_by_pattern(xhp,
xhp->pkgdb, pkg, NULL);
else else
rv = xbps_remove_pkg_from_array_by_name(xhp->pkgdb, pkg, NULL); rv = xbps_remove_pkg_from_array_by_name(xhp,
xhp->pkgdb, pkg, NULL);
if (!flush || !rv) if (!flush || !rv)
return rv; return rv;

View File

@ -40,7 +40,8 @@
* all library functions. * all library functions.
*/ */
static prop_dictionary_t static prop_dictionary_t
find_pkg_in_array(prop_array_t array, find_pkg_in_array(struct xbps_handle *xhp,
prop_array_t array,
const char *str, const char *str,
bool bypattern, bool bypattern,
bool virtual, bool virtual,
@ -61,7 +62,7 @@ find_pkg_in_array(prop_array_t array,
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
chkarch = prop_dictionary_get_cstring_nocopy(obj, chkarch = prop_dictionary_get_cstring_nocopy(obj,
"architecture", &arch); "architecture", &arch);
if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) if (chkarch && !xbps_pkg_arch_match(xhp, arch, targetarch))
continue; continue;
if (virtual) { if (virtual) {
@ -99,21 +100,27 @@ find_pkg_in_array(prop_array_t array,
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_in_array_by_name(prop_array_t array, const char *name, xbps_find_pkg_in_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name,
const char *targetarch) const char *targetarch)
{ {
return find_pkg_in_array(array, name, false, false, targetarch); return find_pkg_in_array(xhp, array, name, false, false, targetarch);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_in_array_by_pattern(prop_array_t array, const char *pattern, xbps_find_pkg_in_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *pattern,
const char *targetarch) const char *targetarch)
{ {
return find_pkg_in_array(array, pattern, true, false, targetarch); return find_pkg_in_array(xhp, array, pattern, true, false, targetarch);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_in_array_by_pkgver(prop_array_t array, const char *pkgver, xbps_find_pkg_in_array_by_pkgver(struct xbps_handle *xhp,
prop_array_t array,
const char *pkgver,
const char *targetarch) const char *targetarch)
{ {
prop_object_iterator_t iter; prop_object_iterator_t iter;
@ -134,7 +141,7 @@ xbps_find_pkg_in_array_by_pkgver(prop_array_t array, const char *pkgver,
if (!prop_dictionary_get_cstring_nocopy(obj, if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &rpkgver)) "pkgver", &rpkgver))
continue; continue;
if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) if (chkarch && !xbps_pkg_arch_match(xhp, arch, targetarch))
continue; continue;
if (strcmp(pkgver, rpkgver) == 0) { if (strcmp(pkgver, rpkgver) == 0) {
found = true; found = true;
@ -149,15 +156,19 @@ xbps_find_pkg_in_array_by_pkgver(prop_array_t array, const char *pkgver,
} }
prop_dictionary_t prop_dictionary_t
xbps_find_virtualpkg_in_array_by_name(prop_array_t array, const char *name) xbps_find_virtualpkg_in_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name)
{ {
return find_pkg_in_array(array, name, false, true, NULL); return find_pkg_in_array(xhp, array, name, false, true, NULL);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_virtualpkg_in_array_by_pattern(prop_array_t array, const char *pattern) xbps_find_virtualpkg_in_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *pattern)
{ {
return find_pkg_in_array(array, pattern, true, true, NULL); return find_pkg_in_array(xhp, array, pattern, true, true, NULL);
} }
static const char * static const char *
@ -230,7 +241,7 @@ find_virtualpkg_user_in_array(struct xbps_handle *xhp,
if (vpkgname == NULL) if (vpkgname == NULL)
return NULL; return NULL;
return find_pkg_in_array(array, vpkgname, false, false, NULL); return find_pkg_in_array(xhp, array, vpkgname, false, false, NULL);
} }
prop_dictionary_t HIDDEN prop_dictionary_t HIDDEN
@ -250,7 +261,8 @@ xbps_find_virtualpkg_conf_in_array_by_pattern(struct xbps_handle *xhp,
} }
static prop_dictionary_t static prop_dictionary_t
find_pkg_in_dict(prop_dictionary_t d, find_pkg_in_dict(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *str, const char *str,
bool bypattern, bool bypattern,
@ -266,27 +278,30 @@ find_pkg_in_dict(prop_dictionary_t d,
if (prop_object_type(array) != PROP_TYPE_ARRAY) if (prop_object_type(array) != PROP_TYPE_ARRAY)
return NULL; return NULL;
return find_pkg_in_array(array, str, bypattern, virtual, NULL); return find_pkg_in_array(xhp, array, str, bypattern, virtual, NULL);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_in_dict_by_name(prop_dictionary_t d, xbps_find_pkg_in_dict_by_name(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *pkgname) const char *pkgname)
{ {
return find_pkg_in_dict(d, key, pkgname, false, false); return find_pkg_in_dict(xhp, d, key, pkgname, false, false);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_in_dict_by_pattern(prop_dictionary_t d, xbps_find_pkg_in_dict_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *pattern) const char *pattern)
{ {
return find_pkg_in_dict(d, key, pattern, true, false); return find_pkg_in_dict(xhp, d, key, pattern, true, false);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t d, xbps_find_pkg_in_dict_by_pkgver(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *pkgver) const char *pkgver)
{ {
@ -300,23 +315,25 @@ xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t d,
if (array == NULL) if (array == NULL)
return NULL; return NULL;
return xbps_find_pkg_in_array_by_pkgver(array, pkgver, NULL); return xbps_find_pkg_in_array_by_pkgver(xhp, array, pkgver, NULL);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d, xbps_find_virtualpkg_in_dict_by_name(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *name) const char *name)
{ {
return find_pkg_in_dict(d, key, name, false, true); return find_pkg_in_dict(xhp, d, key, name, false, true);
} }
prop_dictionary_t prop_dictionary_t
xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d, xbps_find_virtualpkg_in_dict_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key, const char *key,
const char *pattern) const char *pattern)
{ {
return find_pkg_in_dict(d, key, pattern, true, true); return find_pkg_in_dict(xhp, d, key, pattern, true, true);
} }
static prop_dictionary_t static prop_dictionary_t
@ -342,15 +359,15 @@ find_pkgd_installed(struct xbps_handle *xhp,
/* try normal pkg */ /* try normal pkg */
if (virtual == false) { if (virtual == false) {
pkgd = pkgd = find_pkg_in_array(xhp, xhp->pkgdb, str,
find_pkg_in_array(xhp->pkgdb, str, bypattern, false, NULL); bypattern, false, NULL);
} else { } else {
/* virtual pkg set by user in conf */ /* virtual pkg set by user in conf */
pkgd = find_virtualpkg_user_in_array(xhp, xhp->pkgdb, pkgd = find_virtualpkg_user_in_array(xhp, xhp->pkgdb,
str, bypattern); str, bypattern);
if (pkgd == NULL) { if (pkgd == NULL) {
/* any virtual pkg in array matching pattern */ /* any virtual pkg in array matching pattern */
pkgd = find_pkg_in_array(xhp->pkgdb, pkgd = find_pkg_in_array(xhp, xhp->pkgdb,
str, bypattern, true, NULL); str, bypattern, true, NULL);
} }
} }

View File

@ -40,7 +40,10 @@
* all library functions. * all library functions.
*/ */
static bool static bool
remove_obj_from_array(prop_array_t array, const char *str, int mode, remove_obj_from_array(struct xbps_handle *xhp,
prop_array_t array,
const char *str,
int mode,
const char *targetarch) const char *targetarch)
{ {
prop_object_iterator_t iter; prop_object_iterator_t iter;
@ -79,7 +82,8 @@ remove_obj_from_array(prop_array_t array, const char *str, int mode,
/* match by pkgname, obj is a dictionary */ /* match by pkgname, obj is a dictionary */
chkarch = prop_dictionary_get_cstring_nocopy(obj, chkarch = prop_dictionary_get_cstring_nocopy(obj,
"architecture", &arch); "architecture", &arch);
if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) { if (chkarch && !xbps_pkg_arch_match(xhp, arch,
targetarch)) {
idx++; idx++;
continue; continue;
} }
@ -92,7 +96,8 @@ remove_obj_from_array(prop_array_t array, const char *str, int mode,
} else if (mode == 3) { } else if (mode == 3) {
chkarch = prop_dictionary_get_cstring_nocopy(obj, chkarch = prop_dictionary_get_cstring_nocopy(obj,
"architecture", &arch); "architecture", &arch);
if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) { if (chkarch && !xbps_pkg_arch_match(xhp, arch,
targetarch)) {
idx++; idx++;
continue; continue;
} }
@ -106,7 +111,8 @@ remove_obj_from_array(prop_array_t array, const char *str, int mode,
} else if (mode == 4) { } else if (mode == 4) {
chkarch = prop_dictionary_get_cstring_nocopy(obj, chkarch = prop_dictionary_get_cstring_nocopy(obj,
"architecture", &arch); "architecture", &arch);
if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) { if (chkarch && !xbps_pkg_arch_match(xhp, arch,
targetarch)) {
idx++; idx++;
continue; continue;
} }
@ -132,34 +138,44 @@ remove_obj_from_array(prop_array_t array, const char *str, int mode,
} }
bool bool
xbps_remove_string_from_array(prop_array_t array, const char *str) xbps_remove_string_from_array(struct xbps_handle *xhp,
prop_array_t array,
const char *str)
{ {
return remove_obj_from_array(array, str, 0, NULL); return remove_obj_from_array(xhp, array, str, 0, NULL);
} }
bool bool
xbps_remove_pkgname_from_array(prop_array_t array, const char *name) xbps_remove_pkgname_from_array(struct xbps_handle *xhp,
prop_array_t array,
const char *name)
{ {
return remove_obj_from_array(array, name, 1, NULL); return remove_obj_from_array(xhp, array, name, 1, NULL);
} }
bool bool
xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name, xbps_remove_pkg_from_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name,
const char *targetarch) const char *targetarch)
{ {
return remove_obj_from_array(array, name, 2, targetarch); return remove_obj_from_array(xhp, array, name, 2, targetarch);
} }
bool bool
xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, const char *pkgver, xbps_remove_pkg_from_array_by_pkgver(struct xbps_handle *xhp,
prop_array_t array,
const char *pkgver,
const char *targetarch) const char *targetarch)
{ {
return remove_obj_from_array(array, pkgver, 3, targetarch); return remove_obj_from_array(xhp, array, pkgver, 3, targetarch);
} }
bool bool
xbps_remove_pkg_from_array_by_pattern(prop_array_t array, const char *p, xbps_remove_pkg_from_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *p,
const char *targetarch) const char *targetarch)
{ {
return remove_obj_from_array(array, p, 4, targetarch); return remove_obj_from_array(xhp, array, p, 4, targetarch);
} }

View File

@ -310,9 +310,9 @@ find_repo_deps(struct xbps_handle *xhp,
* added in the transaction dictionary. * added in the transaction dictionary.
*/ */
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps"); unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (((curpkgd = xbps_find_pkg_in_array_by_pattern(unsorted, reqpkg, NULL)) == NULL) && if (((curpkgd = xbps_find_pkg_in_array_by_pattern(xhp, unsorted, reqpkg, NULL)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(xhp, unsorted, reqpkg)) == NULL) && ((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(xhp, unsorted, reqpkg)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_in_array_by_pattern(unsorted, reqpkg)) == NULL)) { ((curpkgd = xbps_find_virtualpkg_in_array_by_pattern(xhp, unsorted, reqpkg)) == NULL)) {
/* error matching required pkgdep */ /* error matching required pkgdep */
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
rv = errno; rv = errno;

View File

@ -56,11 +56,11 @@ repo_find_virtualpkg_cb(struct xbps_handle *xhp,
if (rpf->bypattern) { if (rpf->bypattern) {
rpf->pkgd = rpf->pkgd =
xbps_find_virtualpkg_in_array_by_pattern(rpi->repo, xbps_find_virtualpkg_in_array_by_pattern(xhp, rpi->repo,
rpf->pattern); rpf->pattern);
} else { } else {
rpf->pkgd = rpf->pkgd =
xbps_find_virtualpkg_in_array_by_name(rpi->repo, xbps_find_virtualpkg_in_array_by_name(xhp, rpi->repo,
rpf->pattern); rpf->pattern);
} }
if (rpf->pkgd) { if (rpf->pkgd) {
@ -110,15 +110,15 @@ repo_find_pkg_cb(struct xbps_handle *xhp,
if (rpf->exact) { if (rpf->exact) {
/* exact match by pkgver */ /* exact match by pkgver */
rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(rpi->repo, rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(xhp, rpi->repo,
rpf->pattern, NULL); rpf->pattern, NULL);
} else if (rpf->bypattern) { } else if (rpf->bypattern) {
/* match by pkgpattern in pkgver*/ /* match by pkgpattern in pkgver*/
rpf->pkgd = xbps_find_pkg_in_array_by_pattern(rpi->repo, rpf->pkgd = xbps_find_pkg_in_array_by_pattern(xhp, rpi->repo,
rpf->pattern, NULL); rpf->pattern, NULL);
} else { } else {
/* match by pkgname */ /* match by pkgname */
rpf->pkgd = xbps_find_pkg_in_array_by_name(rpi->repo, rpf->pkgd = xbps_find_pkg_in_array_by_name(xhp, rpi->repo,
rpf->pattern, NULL); rpf->pattern, NULL);
} }
if (rpf->pkgd) { if (rpf->pkgd) {
@ -148,10 +148,10 @@ repo_find_best_pkg_cb(struct xbps_handle *xhp,
(void)xhp; (void)xhp;
if (rpf->bypattern) { if (rpf->bypattern) {
pkgd = xbps_find_pkg_in_array_by_pattern(rpi->repo, pkgd = xbps_find_pkg_in_array_by_pattern(xhp, rpi->repo,
rpf->pattern, NULL); rpf->pattern, NULL);
} else { } else {
pkgd = xbps_find_pkg_in_array_by_name(rpi->repo, pkgd = xbps_find_pkg_in_array_by_name(xhp, rpi->repo,
rpf->pattern, NULL); rpf->pattern, NULL);
} }
if (pkgd == NULL) { if (pkgd == NULL) {

View File

@ -108,7 +108,7 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
* transaction and it's going to be updated. * transaction and it's going to be updated.
*/ */
reppkgd = xbps_find_pkg_in_array_by_name( reppkgd = xbps_find_pkg_in_array_by_name(
transd_unsorted, curpkgname, NULL); xhp, transd_unsorted, curpkgname, NULL);
if (reppkgd) { if (reppkgd) {
xbps_dbg_printf(xhp, xbps_dbg_printf(xhp,
"found replaced pkg " "found replaced pkg "

View File

@ -145,7 +145,7 @@ pkgdep_alloc(prop_dictionary_t d, const char *name, const char *trans)
} }
static void static void
pkgdep_end(prop_array_t sorted) pkgdep_end(struct xbps_handle *xhp, prop_array_t sorted)
{ {
prop_dictionary_t d; prop_dictionary_t d;
struct pkgdep *pd; struct pkgdep *pd;
@ -155,12 +155,12 @@ pkgdep_end(prop_array_t sorted)
TAILQ_REMOVE(&pkgdep_list, pd, pkgdep_entries); TAILQ_REMOVE(&pkgdep_list, pd, pkgdep_entries);
if (sorted != NULL && pd->d != NULL) { if (sorted != NULL && pd->d != NULL) {
/* do not add duplicates due to vpkgs */ /* do not add duplicates due to vpkgs */
d = xbps_find_pkg_in_array_by_name(sorted, d = xbps_find_pkg_in_array_by_name(xhp, sorted,
pd->name, NULL); pd->name, NULL);
if (d == NULL) { if (d == NULL) {
/* find a virtual pkg otherwise */ /* find a virtual pkg otherwise */
d = xbps_find_virtualpkg_in_array_by_name( d = xbps_find_virtualpkg_in_array_by_name(
sorted, pd->name); xhp, sorted, pd->name);
if (d == NULL) { if (d == NULL) {
prop_array_add(sorted, pd->d); prop_array_add(sorted, pd->d);
pkgdep_release(pd); pkgdep_release(pd);
@ -232,13 +232,13 @@ again:
continue; continue;
} }
/* Find pkg by name */ /* Find pkg by name */
curpkgd = xbps_find_pkg_in_dict_by_name(xhp->transd, curpkgd = xbps_find_pkg_in_dict_by_name(xhp, xhp->transd,
"unsorted_deps", pkgnamedep); "unsorted_deps", pkgnamedep);
if (curpkgd == NULL) { if (curpkgd == NULL) {
/* find virtualpkg by name if no match */ /* find virtualpkg by name if no match */
curpkgd = curpkgd =
xbps_find_virtualpkg_in_dict_by_name(xhp->transd, xbps_find_virtualpkg_in_dict_by_name(xhp,
"unsorted_deps", pkgnamedep); xhp->transd, "unsorted_deps", pkgnamedep);
} }
if (curpkgd == NULL) { if (curpkgd == NULL) {
free(pkgnamedep); free(pkgnamedep);
@ -343,7 +343,7 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
*/ */
pd = pkgdep_alloc(obj, pkgname, tract); pd = pkgdep_alloc(obj, pkgname, tract);
if (pd == NULL) { if (pd == NULL) {
pkgdep_end(NULL); pkgdep_end(xhp, NULL);
rv = ENOMEM; rv = ENOMEM;
goto out; goto out;
} }
@ -371,7 +371,7 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
* Sort package run-time dependencies for this package. * Sort package run-time dependencies for this package.
*/ */
if ((rv = sort_pkg_rundeps(xhp, pd, rundeps)) != 0) { if ((rv = sort_pkg_rundeps(xhp, pd, rundeps)) != 0) {
pkgdep_end(NULL); pkgdep_end(xhp, NULL);
goto out; goto out;
} }
cnt++; cnt++;
@ -381,7 +381,7 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
* from the sorted list into the "packages" array, and at * from the sorted list into the "packages" array, and at
* the same time freeing memory used for temporary sorting. * the same time freeing memory used for temporary sorting.
*/ */
pkgdep_end(sorted); pkgdep_end(xhp, sorted);
/* /*
* Sanity check that the array contains the same number of * Sanity check that the array contains the same number of
* objects than the total number of required dependencies. * objects than the total number of required dependencies.

View File

@ -281,13 +281,12 @@ xbps_pkg_has_rundeps(prop_dictionary_t pkgd)
} }
bool bool
xbps_pkg_arch_match(const char *orig, const char *target) xbps_pkg_arch_match(struct xbps_handle *xhp,
const char *orig,
const char *target)
{ {
struct utsname un;
if (target == NULL) { if (target == NULL) {
uname(&un); if (strcmp(orig, "noarch") && strcmp(orig, xhp->un_machine))
if (strcmp(orig, "noarch") && strcmp(orig, un.machine))
return false; return false;
} else { } else {
if (strcmp(orig, "noarch") && strcmp(orig, target)) if (strcmp(orig, "noarch") && strcmp(orig, target))

View File

@ -62,14 +62,17 @@ ATF_TC_HEAD(find_pkg_in_array_by_name_test, tc)
} }
ATF_TC_BODY(find_pkg_in_array_by_name_test, tc) ATF_TC_BODY(find_pkg_in_array_by_name_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t dr; prop_dictionary_t dr;
a = prop_array_internalize(arrayxml); a = prop_array_internalize(arrayxml);
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* match by pkgname */ /* match by pkgname */
dr = xbps_find_pkg_in_array_by_name(a, "foo", NULL); dr = xbps_find_pkg_in_array_by_name(&xh, a, "foo", NULL);
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
} }
@ -80,14 +83,17 @@ ATF_TC_HEAD(find_pkg_in_array_by_pattern_test, tc)
} }
ATF_TC_BODY(find_pkg_in_array_by_pattern_test, tc) ATF_TC_BODY(find_pkg_in_array_by_pattern_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t dr; prop_dictionary_t dr;
a = prop_array_internalize(arrayxml); a = prop_array_internalize(arrayxml);
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* match by pkgpattern */ /* match by pkgpattern */
dr = xbps_find_pkg_in_array_by_pattern(a, "foo>=2.0", NULL); dr = xbps_find_pkg_in_array_by_pattern(&xh, a, "foo>=2.0", NULL);
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
} }
@ -98,14 +104,17 @@ ATF_TC_HEAD(find_pkg_in_array_by_pkgver_test, tc)
} }
ATF_TC_BODY(find_pkg_in_array_by_pkgver_test, tc) ATF_TC_BODY(find_pkg_in_array_by_pkgver_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t dr; prop_dictionary_t dr;
a = prop_array_internalize(arrayxml); a = prop_array_internalize(arrayxml);
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* exact match by pkgver */ /* exact match by pkgver */
dr = xbps_find_pkg_in_array_by_pkgver(a, "foo-2.0", NULL); dr = xbps_find_pkg_in_array_by_pkgver(&xh, a, "foo-2.0", NULL);
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
} }
@ -116,6 +125,7 @@ ATF_TC_HEAD(find_virtualpkg_in_array_by_name_test, tc)
} }
ATF_TC_BODY(find_virtualpkg_in_array_by_name_test, tc) ATF_TC_BODY(find_virtualpkg_in_array_by_name_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t dr; prop_dictionary_t dr;
const char *pkgname; const char *pkgname;
@ -123,7 +133,9 @@ ATF_TC_BODY(find_virtualpkg_in_array_by_name_test, tc)
a = prop_array_internalize(arrayxml); a = prop_array_internalize(arrayxml);
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
dr = xbps_find_virtualpkg_in_array_by_name(a, "virtualpkg"); memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
dr = xbps_find_virtualpkg_in_array_by_name(&xh, a, "virtualpkg");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname);
ATF_REQUIRE_STREQ(pkgname, "afoo"); ATF_REQUIRE_STREQ(pkgname, "afoo");
@ -136,6 +148,7 @@ ATF_TC_HEAD(find_virtualpkg_in_array_by_pattern_test, tc)
} }
ATF_TC_BODY(find_virtualpkg_in_array_by_pattern_test, tc) ATF_TC_BODY(find_virtualpkg_in_array_by_pattern_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t dr; prop_dictionary_t dr;
const char *pkgname; const char *pkgname;
@ -143,7 +156,9 @@ ATF_TC_BODY(find_virtualpkg_in_array_by_pattern_test, tc)
a = prop_array_internalize(arrayxml); a = prop_array_internalize(arrayxml);
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
dr = xbps_find_virtualpkg_in_array_by_pattern(a, "virtualpkg>=9999"); memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
dr = xbps_find_virtualpkg_in_array_by_pattern(&xh, a, "virtualpkg>=9999");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname);
ATF_REQUIRE_STREQ(pkgname, "afoo"); ATF_REQUIRE_STREQ(pkgname, "afoo");

View File

@ -65,13 +65,16 @@ ATF_TC_HEAD(find_pkg_in_dict_by_name_test, tc)
} }
ATF_TC_BODY(find_pkg_in_dict_by_name_test, tc) ATF_TC_BODY(find_pkg_in_dict_by_name_test, tc)
{ {
struct xbps_handle xh;
prop_dictionary_t d, dr; prop_dictionary_t d, dr;
d = prop_dictionary_internalize(dictxml); d = prop_dictionary_internalize(dictxml);
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* match by pkgname */ /* match by pkgname */
dr = xbps_find_pkg_in_dict_by_name(d, "packages", "foo"); dr = xbps_find_pkg_in_dict_by_name(&xh, d, "packages", "foo");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
} }
@ -82,13 +85,16 @@ ATF_TC_HEAD(find_pkg_in_dict_by_pattern_test, tc)
} }
ATF_TC_BODY(find_pkg_in_dict_by_pattern_test, tc) ATF_TC_BODY(find_pkg_in_dict_by_pattern_test, tc)
{ {
struct xbps_handle xh;
prop_dictionary_t d, dr; prop_dictionary_t d, dr;
d = prop_dictionary_internalize(dictxml); d = prop_dictionary_internalize(dictxml);
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* match by pkgpattern */ /* match by pkgpattern */
dr = xbps_find_pkg_in_dict_by_pattern(d, "packages", "foo>=2.0"); dr = xbps_find_pkg_in_dict_by_pattern(&xh, d, "packages", "foo>=2.0");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
} }
@ -99,13 +105,16 @@ ATF_TC_HEAD(find_pkg_in_dict_by_pkgver_test, tc)
} }
ATF_TC_BODY(find_pkg_in_dict_by_pkgver_test, tc) ATF_TC_BODY(find_pkg_in_dict_by_pkgver_test, tc)
{ {
struct xbps_handle xh;
prop_dictionary_t d, dr; prop_dictionary_t d, dr;
d = prop_dictionary_internalize(dictxml); d = prop_dictionary_internalize(dictxml);
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* exact match by pkgver */ /* exact match by pkgver */
dr = xbps_find_pkg_in_dict_by_pkgver(d, "packages", "foo-2.0_1"); dr = xbps_find_pkg_in_dict_by_pkgver(&xh, d, "packages", "foo-2.0_1");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
} }
@ -116,6 +125,7 @@ ATF_TC_HEAD(find_virtualpkg_in_dict_by_pattern_test, tc)
} }
ATF_TC_BODY(find_virtualpkg_in_dict_by_pattern_test, tc) ATF_TC_BODY(find_virtualpkg_in_dict_by_pattern_test, tc)
{ {
struct xbps_handle xh;
prop_dictionary_t d, dr; prop_dictionary_t d, dr;
const char *pkgver; const char *pkgver;
@ -123,12 +133,14 @@ ATF_TC_BODY(find_virtualpkg_in_dict_by_pattern_test, tc)
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
/* match virtualpkg by pattern */ /* match virtualpkg by pattern */
dr = xbps_find_virtualpkg_in_dict_by_pattern(d, "packages", "virtualpkg>=9999"); memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
dr = xbps_find_virtualpkg_in_dict_by_pattern(&xh, d, "packages", "virtualpkg>=9999");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver);
ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1"); ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1");
dr = xbps_find_virtualpkg_in_dict_by_pattern(d, "packages", "virtualpkg<=9999_1"); dr = xbps_find_virtualpkg_in_dict_by_pattern(&xh, d, "packages", "virtualpkg<=9999_1");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver);
ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1"); ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1");
@ -141,14 +153,17 @@ ATF_TC_HEAD(find_virtualpkg_in_dict_by_name_test, tc)
} }
ATF_TC_BODY(find_virtualpkg_in_dict_by_name_test, tc) ATF_TC_BODY(find_virtualpkg_in_dict_by_name_test, tc)
{ {
struct xbps_handle xh;
prop_dictionary_t d, dr; prop_dictionary_t d, dr;
const char *pkgver; const char *pkgver;
d = prop_dictionary_internalize(dictxml); d = prop_dictionary_internalize(dictxml);
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
/* match virtualpkg by name */ /* match virtualpkg by name */
dr = xbps_find_virtualpkg_in_dict_by_name(d, "packages", "virtualpkg"); dr = xbps_find_virtualpkg_in_dict_by_name(&xh, d, "packages", "virtualpkg");
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver);
ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1"); ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1");

View File

@ -25,6 +25,7 @@
*/ */
#include <atf-c.h> #include <atf-c.h>
#include <xbps_api.h> #include <xbps_api.h>
#include <string.h>
static const char dictxml[] = static const char dictxml[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@ -100,6 +101,7 @@ ATF_TC_HEAD(remove_pkg_from_array_by_name_test, tc)
ATF_TC_BODY(remove_pkg_from_array_by_name_test, tc) ATF_TC_BODY(remove_pkg_from_array_by_name_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t d, d2; prop_dictionary_t d, d2;
@ -109,8 +111,10 @@ ATF_TC_BODY(remove_pkg_from_array_by_name_test, tc)
d2 = prop_dictionary_internalize(dictxml2); d2 = prop_dictionary_internalize(dictxml2);
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
a = prop_dictionary_get(d, "packages"); a = prop_dictionary_get(d, "packages");
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_name(a, "afoo", NULL), true); ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_name(&xh, a, "afoo", NULL), true);
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true); ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
} }
@ -123,6 +127,7 @@ ATF_TC_HEAD(remove_pkg_from_array_by_pattern_test, tc)
ATF_TC_BODY(remove_pkg_from_array_by_pattern_test, tc) ATF_TC_BODY(remove_pkg_from_array_by_pattern_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t d, d2; prop_dictionary_t d, d2;
@ -132,8 +137,10 @@ ATF_TC_BODY(remove_pkg_from_array_by_pattern_test, tc)
d2 = prop_dictionary_internalize(dictxml2); d2 = prop_dictionary_internalize(dictxml2);
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
a = prop_dictionary_get(d, "packages"); a = prop_dictionary_get(d, "packages");
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pattern(a, "afoo>=1.0", NULL), true); ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pattern(&xh, a, "afoo>=1.0", NULL), true);
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true); ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
} }
@ -146,6 +153,7 @@ ATF_TC_HEAD(remove_pkg_from_array_by_pkgver_test, tc)
ATF_TC_BODY(remove_pkg_from_array_by_pkgver_test, tc) ATF_TC_BODY(remove_pkg_from_array_by_pkgver_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a; prop_array_t a;
prop_dictionary_t d, d2; prop_dictionary_t d, d2;
@ -155,8 +163,10 @@ ATF_TC_BODY(remove_pkg_from_array_by_pkgver_test, tc)
d2 = prop_dictionary_internalize(dictxml2); d2 = prop_dictionary_internalize(dictxml2);
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY); ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
a = prop_dictionary_get(d, "packages"); a = prop_dictionary_get(d, "packages");
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pkgver(a, "afoo-1.1_1", NULL), true); ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pkgver(&xh, a, "afoo-1.1_1", NULL), true);
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true); ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
} }
@ -169,6 +179,7 @@ ATF_TC_HEAD(remove_string_from_array_test, tc)
ATF_TC_BODY(remove_string_from_array_test, tc) ATF_TC_BODY(remove_string_from_array_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a, a2; prop_array_t a, a2;
a = prop_array_internalize(axml); a = prop_array_internalize(axml);
@ -177,7 +188,9 @@ ATF_TC_BODY(remove_string_from_array_test, tc)
a2 = prop_array_internalize(axml2); a2 = prop_array_internalize(axml2);
ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY);
ATF_REQUIRE_EQ(xbps_remove_string_from_array(a, "foo-1.0_1"), true); memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
ATF_REQUIRE_EQ(xbps_remove_string_from_array(&xh, a, "foo-1.0_1"), true);
ATF_REQUIRE_EQ(prop_array_equals(a, a2), true); ATF_REQUIRE_EQ(prop_array_equals(a, a2), true);
} }
@ -190,6 +203,7 @@ ATF_TC_HEAD(remove_pkgname_from_array_test, tc)
ATF_TC_BODY(remove_pkgname_from_array_test, tc) ATF_TC_BODY(remove_pkgname_from_array_test, tc)
{ {
struct xbps_handle xh;
prop_array_t a, a2; prop_array_t a, a2;
a = prop_array_internalize(axml); a = prop_array_internalize(axml);
@ -198,7 +212,9 @@ ATF_TC_BODY(remove_pkgname_from_array_test, tc)
a2 = prop_array_internalize(axml2); a2 = prop_array_internalize(axml2);
ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY); ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY);
ATF_REQUIRE_EQ(xbps_remove_pkgname_from_array(a, "foo"), true); memset(&xh, 0, sizeof(xh));
xbps_init(&xh);
ATF_REQUIRE_EQ(xbps_remove_pkgname_from_array(&xh, a, "foo"), true);
ATF_REQUIRE_EQ(prop_array_equals(a, a2), true); ATF_REQUIRE_EQ(prop_array_equals(a, a2), true);
} }