[pacman-dev] [PATCH] Strip leading "/" from arguments to --overwrite

Joey Pabalinas joeypabalinas at gmail.com
Fri Jun 1 23:01:36 UTC 2018


On Fri, Jun 01, 2018 at 06:56:13PM -0400, Andrew Gregory wrote:
> Sort of.  The current --root option is a confusing mess that nobody
> actually understands, so it will go away at some point.  The
> underlying libalpm rootdir setting isn't going anywhere though, and,
> in the future, will be configured with a new --rootdir option.

Well looking at the code it actually isn't as complicated as I thought it
would be.

How about something like this:

> case OP_OVERWRITE_FILES:
> 	{
> 		char *i, *root = config->rootdir, *save = NULL;
> 		for(i = strtok_r(optarg, ",", &save); i; i = strtok_r(NULL, ",", &save)) {
> 			/* strip rootdir if applicable */
> 			if (root && !memcmp(i, root, strlen(root)))
> 				i += strlen(root);
> 			/* strip remaining leading "/" before adding to option list */
> 			i += strspn(i, "/");
> 			config->overwrite_files = alpm_list_add(config->overwrite_files, strdup(i));
> 		}
>	}

which would strip the rootdir and then the leading "/". Although I am not
100% certain config->rootdir would be NULL if no argument is passed; could
you confirm that part?

-- 
Cheers,
Joey Pabalinas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20180601/04703318/attachment.asc>


More information about the pacman-dev mailing list