diff mbox

[pacman-dev] src/pacman: strip any leading / in --overwrite arguments

Message ID 20180601095001.zbphszxzt4nb6arr@gmail.com
State Rejected, archived
Headers show

Commit Message

Joey Pabalinas June 1, 2018, 9:50 a.m. UTC
Allow both `pacman -S foo --overwrite /usr/lib/foo.sh` and
`pacman -S foo --overwrite usr/lib/foo.sh` (with any number
of leading / ignored) to semantically mean the same thing.

Update the documentation to reflect this change.

Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>

 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Eli Schwartz June 1, 2018, 11:38 a.m. UTC | #1
On 06/01/2018 05:50 AM, Joey Pabalinas wrote:
> Allow both `pacman -S foo --overwrite /usr/lib/foo.sh` and
> `pacman -S foo --overwrite usr/lib/foo.sh` (with any number
> of leading / ignored) to semantically mean the same thing.

Already done in
https://lists.archlinux.org/pipermail/pacman-dev/2018-May/022515.html

> Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>

> @@ -317,10 +317,12 @@ static void invalid_opt(int used, const char *opt1, const char *opt2)
>  static int parsearg_util_addlist(alpm_list_t **list)
>  {
>  	char *i, *save = NULL;
>  
>  	for(i = strtok_r(optarg, ",", &save); i; i = strtok_r(NULL, ",", &save)) {
> +		/* strip any leading slashes */
> +		i += strspn(i, "/");
>  		*list = alpm_list_add(*list, strdup(i));
>  	}
>  
>  	return 0;
>  }

This function is used in several places, where it refers to package
names or groups. I would expect --ignore=/foo to not work, rather than
be replaced by "foo". We should not be modifying this function for every
use...
diff mbox

Patch

diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc
index b6f4dd76e1249fd0ec..1bafe3c3c1aedb0051 100644
--- a/doc/pacman.8.asciidoc
+++ b/doc/pacman.8.asciidoc
@@ -263,12 +263,13 @@  Upgrade Options (apply to '-S' and '-U')[[UO]]
 	overwritten.  Using '\--overwrite' will not allow overwriting a directory
 	with a file or installing packages with conflicting files and directories.
 	Multiple patterns can be specified by separating them with a comma. May be
 	specified multiple times.  Patterns can be negated, such that files
 	matching them will not be overwritten, by prefixing them with an
-	exclamation mark. Subsequent matches will override previous ones. A leading
-	literal exclamation mark or backslash needs to be escaped.
+	exclamation mark. Subsequent matches will override previous ones. Any
+	leading slashes in the pattern are ignored. A leading literal exclamation
+	mark or backslash needs to be escaped.
 
 
 Query Options (apply to '-Q')[[QO]]
 -----------------------------------
 *-c, \--changelog*::
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index fe54793ea775c03915..f757b4141601587105 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -317,10 +317,12 @@  static void invalid_opt(int used, const char *opt1, const char *opt2)
 static int parsearg_util_addlist(alpm_list_t **list)
 {
 	char *i, *save = NULL;
 
 	for(i = strtok_r(optarg, ",", &save); i; i = strtok_r(NULL, ",", &save)) {
+		/* strip any leading slashes */
+		i += strspn(i, "/");
 		*list = alpm_list_add(*list, strdup(i));
 	}
 
 	return 0;
 }