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

Dave Reisner d at falconindy.com
Sat Jan 19 11:47:59 EST 2013


On Sat, Jan 19, 2013 at 11:28:47AM -0500, Andrew Gregory wrote:
> 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"
> 

Good catch, thanks. Requires a little more than just the function swap.


More information about the pacman-dev mailing list