1 From: "Stewart Smith" <stewart@flamingspork.com>
2 To: notmuch@notmuchmail.org
3 Date: Wed, 18 Nov 2009 13:22:20 +1100
4 Subject: [notmuch] [PATCH] count_files: sort directory in inode order before
6 Message-ID: <1258510940-7018-1-git-send-email-stewart@flamingspork.com>
9 notmuch-new.c | 30 ++++++++++--------------------
10 1 files changed, 10 insertions(+), 20 deletions(-)
12 diff --git a/notmuch-new.c b/notmuch-new.c
13 index 11fad8c..c5f841a 100644
16 @@ -308,36 +308,26 @@ add_files (notmuch_database_t *notmuch,
18 count_files (const char *path, int *count)
21 - struct dirent *e, *entry = NULL;
24 + struct dirent *entry = NULL;
27 + struct dirent **namelist = NULL;
29 - dir = opendir (path);
30 + int n_entries= scandir(path, &namelist, 0, ino_cmp);
33 + if (n_entries == -1) {
34 fprintf (stderr, "Warning: failed to open directory %s: %s\n",
35 path, strerror (errno));
39 - entry_length = offsetof (struct dirent, d_name) +
40 - pathconf (path, _PC_NAME_MAX) + 1;
41 - entry = malloc (entry_length);
44 while (!interrupted) {
45 - err = readdir_r (dir, entry, &e);
47 - fprintf (stderr, "Error reading directory: %s\n",
57 + entry= namelist[i++];
59 /* Ignore special directories to avoid infinite recursion.
60 * Also ignore the .notmuch directory.
61 @@ -376,8 +366,8 @@ count_files (const char *path, int *count)