[pacman-dev] [PATCH] pacman: don't error when a group exists but all packages are ignored

morganamilo morganamilo at gmail.com
Thu Oct 18 19:45:56 UTC 2018


Currently when attempting to sync a group where all packages are
ignored (either by ignorepkg, ignoregroup or --needed) pacman
will error with "target not found".

Instead, if a group has no packages, check if the group exists
and only throw an error if it does not.

Signed-off-by: morganamilo <morganamilo at gmail.com>

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 2d3d198a..316853bb 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1446,6 +1446,8 @@ int alpm_extract_keyid(alpm_handle_t *handle, const char *identifier,
 
 alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name);
 
+int alpm_group_exists(alpm_list_t *dbs, const char *name);
+
 /*
  * Sync
  */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 05f58fad..57058782 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -313,6 +313,26 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
 	return pkgs;
 }
 
+/** Check if a group exists across a list of databases.
+ * @param dbs the list of alpm_db_t *
+ * @param name the name of the group
+ * @return 1 if the group exists, 0 if it does not
+ */
+int SYMEXPORT alpm_group_exists(alpm_list_t *dbs,
+		const char *name)
+{
+	alpm_list_t *i;
+	for(i = dbs; i; i = i->next) {
+		alpm_db_t *db = i->data;
+
+		if (alpm_db_get_group(db, name)) {
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 /** Compute the size of the files that will be downloaded to install a
  * package.
  * @param newpkg the new package to upgrade to
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ef8faedf..32df6e04 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -543,6 +543,10 @@ static int process_group(alpm_list_t *dbs, const char *group, int error)
 	int count = alpm_list_count(pkgs);
 
 	if(!count) {
+		if(alpm_group_exists(dbs, group)) {
+			return 0;
+		}
+
 		pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), group);
 		return 1;
 	}
-- 
2.19.1


More information about the pacman-dev mailing list