[pacman-dev] [PATCH 1/2] pacsort: add -f, --files option for sorting filenames

Andrew Gregory andrew.gregory.8 at gmail.com
Sat Jan 19 11:28:47 EST 2013


On Sat, 19 Jan 2013 11:06:45 -0500
Dave Reisner <dreisner at archlinux.org> wrote:

<snip>

> +	if(opts.filemode) {
> +		if(fnmatch("*-*.pkg.tar.?z", name1, 0) == 0 &&
> +			 fnmatch("*-*.pkg.tar.?z", name2, 0) == 0) {
> +			char *s, *e;
> +
> +			s = strchr(name1, '/');
> +			e = strrchr(name1, '-');
> +			fn1 = strndup(name1, e - (s ? s : name1));
> +
> +			s = strchr(name2, '/');
> +			e = strrchr(name2, '-');
> +			fn2 = strndup(name2, e - (s ? s : name2));
> +
> +			name1 = fn1;
> +			name2 = fn2;
> +		}
> +	}
> +

If your intent is to remove the entire leading path, those should be:
s = strrchr(nameX, '/');

You could add another test to catch this:

in="/path2/firefox-18.0-2-x86_64.pkg.tar.xz\n/path1/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
runtest $in $in "filename sort with different leading paths" "--files"


More information about the pacman-dev mailing list