[pacman-dev] pacman: better handle -F when file is not found

Message ID 20190909164916.3666-1-morganamilo@gmail.com
State Changes Requested
Headers show
Series
  • [pacman-dev] pacman: better handle -F when file is not found
Related show

Commit Message

morganamilo Sept. 9, 2019, 4:49 p.m. UTC
Error messages are now printed.
Pacman now returns 1 if any of the files queried are not found.
---
 src/pacman/files.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Andrew Gregory Sept. 10, 2019, 3:32 p.m. UTC | #1
On 09/09/19 at 05:49pm, morganamilo wrote:
> Error messages are now printed.
> Pacman now returns 1 if any of the files queried are not found.
> ---
>  src/pacman/files.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/src/pacman/files.c b/src/pacman/files.c
> index 8e518486..c4351114 100644
> --- a/src/pacman/files.c
> +++ b/src/pacman/files.c
> @@ -115,7 +115,6 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
>  
>  		if(regex) {
>  			if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
> -				/* TODO: error message */
>  				goto notfound;

...

>  notfound:
> -		if(!found) {
> -			ret++;
> +		ret = 1;
> +		if(regex) {
> +			pm_printf(ALPM_LOG_ERROR, _("no files match '%s'\n"), targ);

"no files match" isn't really a great error message if the real
problem is that the regex failed to even compile.

Patch

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 8e518486..c4351114 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -115,7 +115,6 @@  static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
 
 		if(regex) {
 			if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
-				/* TODO: error message */
 				goto notfound;
 			}
 		}
@@ -174,13 +173,20 @@  static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
 			regfree(&reg);
 		}
 
+		if(found) {
+			continue;
+		}
+
 notfound:
-		if(!found) {
-			ret++;
+		ret = 1;
+		if(regex) {
+			pm_printf(ALPM_LOG_ERROR, _("no files match '%s'\n"), targ);
+		} else {
+			pm_printf(ALPM_LOG_ERROR, _("no package owns '%s'\n"), targ);
 		}
 	}
 
-	return 0;
+	return ret;
 }
 
 static void dump_file_list(alpm_pkg_t *pkg) {