Fix file importing code to not generate some duplicate directories
authorDan Winship <danw@gnome.org>
Wed Feb 20 12:42:42 2008 -0500 (2008-02-20)
changeset 1263142795705a5
parent 125 e56c83bda295
child 127 4a12eceb0858
Fix file importing code to not generate some duplicate directories

build_file_tree() depends on the fact that the contents of a directory
are sorted immediately after it in the file list, but '.' sorts before '/'
lexicographically, so you'd actually end up with, eg:

/etc/yum
/etc/yum.conf
/etc/yum/pluginconf.d

which would cause a second entry for /etc/yum to be added to the file
list.

For now I've fixed this by make compare_filenames() do a special strcmp
by hand, manually sorting '/' before anything else.
razor.c
     1.1 --- a/razor.c	Fri Feb 15 15:09:37 2008 -0500
     1.2 +++ b/razor.c	Wed Feb 20 12:42:42 2008 -0500
     1.3 @@ -530,8 +530,29 @@
     1.4  {
     1.5  	const struct import_entry *e1 = p1;
     1.6  	const struct import_entry *e2 = p2;
     1.7 +	const char *n1 = e1->name;
     1.8 +	const char *n2 = e2->name;
     1.9  
    1.10 -	return strcmp(e1->name, e2->name);
    1.11 +	/* Need to make sure that the contents of a directory
    1.12 +	 * are sorted immediately after it. So "foo/bar" has to
    1.13 +	 * sort before "foo.conf"
    1.14 +	 *
    1.15 +	 * FIXME: this is about 60% slower than strcmp
    1.16 +	 */
    1.17 +	while (*n1 && *n2) {
    1.18 +		if (*n1 < *n2)
    1.19 +			return *n2 == '/' ? 1 : -1;
    1.20 +		else if (*n1 > *n2)
    1.21 +			return *n1 == '/' ? -1 : 1;
    1.22 +		n1++;
    1.23 +		n2++;
    1.24 +	}
    1.25 +	if (*n1)
    1.26 +		return 1;
    1.27 +	else if (*n2)
    1.28 +		return -1;
    1.29 +	else
    1.30 +		return 0;
    1.31  }
    1.32  
    1.33  static void