From 83bda174abac1de86e16af7eee5c36d317a1d520 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 12 Apr 2012 11:57:21 +0200
Subject: [PATCH] libxbps: make xbps_find_virtualpkg_* only look for virtual
 pkgs.

Before this commit they also looked for non virtual packages, which
is not what it was meant when those functions were added.
---
 include/xbps_api.h       |  2 +-
 lib/package_requiredby.c | 12 ++++++++----
 lib/plist_find.c         | 17 ++++++++---------
 lib/util.c               | 13 ++++++++-----
 4 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/include/xbps_api.h b/include/xbps_api.h
index 0a19ef5a..5d8c67fe 100644
--- a/include/xbps_api.h
+++ b/include/xbps_api.h
@@ -56,7 +56,7 @@
  */
 #define XBPS_PKGINDEX_VERSION	"1.4"
 
-#define XBPS_API_VERSION	"20120410"
+#define XBPS_API_VERSION	"20120412"
 #define XBPS_VERSION		"0.16"
 
 /**
diff --git a/lib/package_requiredby.c b/lib/package_requiredby.c
index 9fc425df..3aa55cc6 100644
--- a/lib/package_requiredby.c
+++ b/lib/package_requiredby.c
@@ -156,10 +156,14 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
 			    xbps_find_virtualpkg_in_array_by_pattern(
 			    xhp->pkgdb, str);
 			if (pkgd_pkgdb == NULL) {
-				rv = ENOENT;
-				xbps_dbg_printf("%s: couldnt find `%s' "
-				     "entry in pkgdb\n", __func__, str);
-				break;
+				pkgd_pkgdb = xbps_find_pkg_in_array_by_pattern(
+				    xhp->pkgdb, str);
+				if (pkgd_pkgdb == NULL) {
+					rv = ENOENT;
+					xbps_dbg_printf("%s: couldnt find `%s' "
+					    "entry in pkgdb\n", __func__, str);
+					break;
+				}
 			}
 		}
 		rv = add_pkg_into_reqby(pkgd_pkgdb, pkgver);
diff --git a/lib/plist_find.c b/lib/plist_find.c
index e25ecff3..cb194e9f 100644
--- a/lib/plist_find.c
+++ b/lib/plist_find.c
@@ -58,7 +58,14 @@ find_pkg_in_array(prop_array_t array,
 		return NULL;
 
 	while ((obj = prop_object_iterator_next(iter))) {
-		if (bypattern) {
+		if (virtual) {
+			/*
+			 * Check if package pattern matches
+			 * any virtual package version in dictionary.
+			 */
+			if (xbps_match_virtual_pkg_in_dict(obj, str, bypattern))
+				break;
+		} else if (bypattern) {
 			/*
 			 * Check if package pattern matches the
 			 * pkgver string object in dictionary.
@@ -75,14 +82,6 @@ find_pkg_in_array(prop_array_t array,
 			if (strcmp(dpkgn, str) == 0)
 				break;
 		}
-		if (!virtual)
-			continue;
-		/*
-		 * Finally check if package pattern matches
-		 * any virtual package version in dictionary.
-		 */
-		if (xbps_match_virtual_pkg_in_dict(obj, str, bypattern))
-			break;
 	}
 	prop_object_iterator_release(iter);
 	if (obj == NULL) {
diff --git a/lib/util.c b/lib/util.c
index 31f1011f..9b2d2fc5 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -68,11 +68,14 @@ xbps_check_is_installed_pkg_by_pattern(const char *pattern)
 
 	dict = xbps_find_virtualpkg_dict_installed(pattern, true);
 	if (dict == NULL) {
-		if (errno == ENOENT) {
-			errno = 0;
-			return 0; /* not installed */
-		}	
-		return -1; /* error */
+		dict = xbps_find_pkg_dict_installed(pattern, true);
+		if (dict == NULL) {
+			if (errno == ENOENT) {
+				errno = 0;
+				return 0; /* not installed */
+			}
+			return -1; /* error */
+		}
 	}
 	/*
 	 * Check that package state is fully installed, not