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

2018-10-18 Thread Andrew Gregory
On 10/18/18 at 08:45pm, morganamilo wrote:
> 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 

Let's put group_exists in the front-end.  We may want to modify it to
take usage or other factors into account and I don't want to have to
figure out how to fit that into a public API, and it's a lot easier to
move it from the front-end to the back-end if we do decide to in the
future than the other way around.

> 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)

No need to break lines under 80 characters.

> +{
> + alpm_list_t *i;
> + for(i = dbs; i; i = i->next) {
> + alpm_db_t *db = i->data;
> +
> + if (alpm_db_get_group(db, name)) {

No space between if and (.

> + 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


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

2018-10-18 Thread morganamilo
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 

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