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.
{
const struct import_entry *e1 = p1;
const struct import_entry *e2 = p2;
-
- return strcmp(e1->name, e2->name);
+ const char *n1 = e1->name;
+ const char *n2 = e2->name;
+
+ /* Need to make sure that the contents of a directory
+ * are sorted immediately after it. So "foo/bar" has to
+ * sort before "foo.conf"
+ *
+ * FIXME: this is about 60% slower than strcmp
+ */
+ while (*n1 && *n2) {
+ if (*n1 < *n2)
+ return *n2 == '/' ? 1 : -1;
+ else if (*n1 > *n2)
+ return *n1 == '/' ? -1 : 1;
+ n1++;
+ n2++;
+ }
+ if (*n1)
+ return 1;
+ else if (*n2)
+ return -1;
+ else
+ return 0;
}
static void