xbps_repository_find_pkg_deps: some performance optimizations.

This commit is contained in:
Juan RP 2011-01-25 18:09:27 +01:00
parent 563b6446f4
commit ac6fe51340

View File

@ -62,7 +62,6 @@ store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkgd)
* Always set "not-installed" package state. Will be overwritten * Always set "not-installed" package state. Will be overwritten
* to its correct state later. * to its correct state later.
*/ */
xbps_dbg_printf_append("\n");
rv = xbps_set_pkg_state_dictionary(dict, XBPS_PKG_STATE_NOT_INSTALLED); rv = xbps_set_pkg_state_dictionary(dict, XBPS_PKG_STATE_NOT_INSTALLED);
if (rv != 0) { if (rv != 0) {
prop_object_release(dict); prop_object_release(dict);
@ -247,7 +246,7 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
pkg_state_t state = 0; pkg_state_t state = 0;
const char *reqpkg, *reqvers, *pkg_queued; const char *reqpkg, *reqvers, *pkg_queued, *repopkgver;
char *pkgname; char *pkgname;
int rv = 0; int rv = 0;
@ -260,34 +259,19 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
* current package. * current package.
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
curpkgd = NULL; tmpd = curpkgd = NULL;
reqpkg = prop_string_cstring_nocopy(obj); reqpkg = prop_string_cstring_nocopy(obj);
if (reqpkg == NULL) { if (reqpkg == NULL) {
rv = EINVAL; rv = EINVAL;
break; break;
} }
if (originpkgn) if (originpkgn)
xbps_dbg_printf(" %s requires dependency '%s' " xbps_dbg_printf("'%s' requires dependency '%s' "
"[direct]: ", originpkgn, reqpkg); "[direct]: ", originpkgn, reqpkg);
else else
xbps_dbg_printf(" requires dependency '%s' " xbps_dbg_printf(" Requires dependency '%s' "
"[indirect]: ", reqpkg); "[indirect]: ", reqpkg);
/*
* Check if required dep is satisfied and installed.
*/
rv = xbps_check_is_installed_pkg(reqpkg);
if (rv == -1) {
/* There was an error checking it... */
xbps_dbg_printf_append("error matching reqdep %s\n",
reqpkg);
break;
} else if (rv == 1) {
/* Required pkg dependency is satisfied */
xbps_dbg_printf_append("satisfied and installed.\n");
rv = 0;
continue;
}
pkgname = xbps_get_pkgpattern_name(reqpkg); pkgname = xbps_get_pkgpattern_name(reqpkg);
if (pkgname == NULL) { if (pkgname == NULL) {
rv = EINVAL; rv = EINVAL;
@ -306,25 +290,25 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
*/ */
curpkgd = xbps_find_pkg_in_dict_by_name(trans_dict, curpkgd = xbps_find_pkg_in_dict_by_name(trans_dict,
"unsorted_deps", pkgname); "unsorted_deps", pkgname);
if (curpkgd == NULL) { if (curpkgd != NULL) {
if (errno && errno != ENOENT) {
free(pkgname);
rv = errno;
break;
}
} else {
prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkg_queued); "pkgver", &pkg_queued);
if (xbps_pkgpattern_match(pkg_queued, if (xbps_pkgpattern_match(pkg_queued,
__UNCONST(reqpkg))) { __UNCONST(reqpkg))) {
xbps_dbg_printf_append( xbps_dbg_printf_append(
"queued in the transaction.\n"); "'%s' queued in the transaction.\n",
pkg_queued);
free(pkgname); free(pkgname);
continue; continue;
} }
curpkgd = NULL; } else {
/* error matching required pkgdep */
if (errno && errno != ENOENT) {
rv = errno;
free(pkgname);
break;
}
} }
/* /*
* If required pkgdep is not in repo, add it into the * If required pkgdep is not in repo, add it into the
* missing deps array and pass to the next one. * missing deps array and pass to the next one.
@ -339,41 +323,48 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
rv = add_missing_reqdep(mrdeps, reqpkg); rv = add_missing_reqdep(mrdeps, reqpkg);
if (rv != 0 && rv != EEXIST) { if (rv != 0 && rv != EEXIST) {
xbps_dbg_printf_append("add missing reqdep " xbps_dbg_printf_append("`%s': "
"failed %s\n", reqpkg); "add_missing_reqdep failed %s\n", reqpkg);
free(pkgname); free(pkgname);
break; break;
} else if (rv == EEXIST) { } else if (rv == EEXIST) {
xbps_dbg_printf_append("missing dep %s " xbps_dbg_printf_append("`%s' missing dep "
"already added.\n", reqpkg); "already added.\n", reqpkg);
rv = 0; rv = 0;
free(pkgname); free(pkgname);
continue; continue;
} else { } else {
xbps_dbg_printf_append( xbps_dbg_printf_append("`%s' added "
"missing dep '%s' in repository!\n", "into the missing deps array.\n", reqpkg);
reqpkg);
free(pkgname); free(pkgname);
continue; continue;
} }
} }
/* /*
* If package is installed but version doesn't satisfy * Check if required pkgdep is installed and matches
* the dependency mark it as an update, otherwise as * the required version.
* an install. Packages that were unpacked previously
* will be marked as pending to be configured.
*/ */
tmpd = xbps_find_pkg_dict_installed(reqpkg, true); tmpd = xbps_find_pkg_dict_installed(pkgname, false);
if (tmpd == NULL) { if (tmpd == NULL) {
free(pkgname);
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
free(pkgname); /* error */
prop_object_release(curpkgd);
rv = errno; rv = errno;
break; break;
} }
/* Required pkgdep not installed */
prop_dictionary_set_cstring_nocopy(curpkgd, prop_dictionary_set_cstring_nocopy(curpkgd,
"trans-action", "install"); "trans-action", "install");
} else if (tmpd) { xbps_dbg_printf_append("not installed.\n");
} else {
/*
* Check if installed version matches the
* required pkgdep version.
*/
prop_dictionary_get_cstring_nocopy(tmpd,
"pkgver", &pkg_queued);
/* Check its state */
rv = xbps_get_pkg_state_installed(pkgname, &state); rv = xbps_get_pkg_state_installed(pkgname, &state);
if (rv != 0) { if (rv != 0) {
free(pkgname); free(pkgname);
@ -381,14 +372,47 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
prop_object_release(curpkgd); prop_object_release(curpkgd);
break; break;
} }
if (state == XBPS_PKG_STATE_INSTALLED) free(pkgname);
if (xbps_pkgpattern_match(pkg_queued,
__UNCONST(reqpkg)) == 0) {
/*
* Package is installed but does not match
* the dependency pattern, an update
* needs to be installed.
*/
prop_dictionary_get_cstring_nocopy(curpkgd,
"version", &repopkgver);
xbps_dbg_printf_append("installed `%s', "
"updating to `%s'...\n",
pkg_queued, repopkgver);
prop_dictionary_set_cstring_nocopy(curpkgd, prop_dictionary_set_cstring_nocopy(curpkgd,
"trans-action", "update"); "trans-action", "update");
else } else {
prop_dictionary_set_cstring_nocopy(curpkgd, if (state == XBPS_PKG_STATE_UNPACKED) {
"trans-action", "configure"); /*
* Package matches the dependency
prop_object_release(tmpd); * pattern but was only unpacked,
* mark pkg to be configured.
*/
prop_dictionary_set_cstring_nocopy(
curpkgd, "trans-action",
"configure");
xbps_dbg_printf_append("installed `%s'"
", but needs to be configured...\n",
pkg_queued);
} else {
/*
* Package matches the dependency
* pattern and is fully installed,
* skip to the next one.
*/
xbps_dbg_printf_append("installed "
"`%s'.\n", pkg_queued);
prop_object_release(tmpd);
prop_object_release(curpkgd);
continue;
}
}
} }
/* /*
* Package is on repo, add it into the dictionary. * Package is on repo, add it into the dictionary.
@ -396,11 +420,9 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
if ((rv = store_dependency(trans_dict, curpkgd)) != 0) { if ((rv = store_dependency(trans_dict, curpkgd)) != 0) {
xbps_dbg_printf("store_dependency failed %s", xbps_dbg_printf("store_dependency failed %s",
reqpkg); reqpkg);
free(pkgname);
prop_object_release(curpkgd); prop_object_release(curpkgd);
break; break;
} }
/* /*
* If package was added in the missing_deps array, we * If package was added in the missing_deps array, we
* can remove it now it has been found in current repository. * can remove it now it has been found in current repository.
@ -413,30 +435,24 @@ find_repo_deps(prop_dictionary_t trans_dict, /* transaction dictionary */
} else { } else {
xbps_dbg_printf("Removing missing dep %s " xbps_dbg_printf("Removing missing dep %s "
"returned %s\n", reqpkg, strerror(rv)); "returned %s\n", reqpkg, strerror(rv));
free(pkgname);
prop_object_release(curpkgd); prop_object_release(curpkgd);
break; break;
} }
/* /*
* If package doesn't have rundeps, pass to the next one. * If package doesn't have rundeps, pass to the next one.
*/ */
curpkg_rdeps = prop_dictionary_get(curpkgd, "run_depends"); curpkg_rdeps = prop_dictionary_get(curpkgd, "run_depends");
if (curpkg_rdeps == NULL) { if (curpkg_rdeps == NULL) {
free(pkgname);
prop_object_release(curpkgd); prop_object_release(curpkgd);
continue; continue;
} }
prop_object_release(curpkgd); prop_object_release(curpkgd);
/* /*
* Iterate on required pkg to find more deps. * Iterate on required pkg to find more deps.
*/ */
xbps_dbg_printf_append("\n"); xbps_dbg_printf("%sFinding dependencies for '%s' [%s]:\n",
xbps_dbg_printf("Finding dependencies for '%s-%s' [%s]:\n", originpkgn ? "" : " ", reqpkg,
pkgname, reqvers, originpkgn ? "direct" : "indirect"); originpkgn ? "direct" : "indirect");
free(pkgname);
rv = find_repo_deps(trans_dict, mrdeps, NULL, curpkg_rdeps); rv = find_repo_deps(trans_dict, mrdeps, NULL, curpkg_rdeps);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf("Error checking %s for rundeps: %s\n", xbps_dbg_printf("Error checking %s for rundeps: %s\n",