From: Dan Winship Date: Wed, 20 Feb 2008 17:37:37 +0000 (-0500) Subject: Fix file importing code to not generate some duplicate directories X-Git-Tag: 0.1~234 X-Git-Url: http://project.juiblex.co.uk/git/?a=commitdiff_plain;h=572a0837d6ea8ebb03ac412572bbeec294b5f1d5;p=razor.git 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. --- diff --git a/razor.c b/razor.c index b5fbf88..b491004 100644 --- a/razor.c +++ b/razor.c @@ -530,8 +530,29 @@ compare_filenames(const void *p1, const void *p2, void *data) { 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