]> git.notmuchmail.org Git - notmuch/blob - test/corpus/30
test: Fix emacs FCC test to account for new maildir synchronization
[notmuch] / test / corpus / 30
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
5         statting
6 Message-ID: <1258510940-7018-1-git-send-email-stewart@flamingspork.com>
7
8 ---
9  notmuch-new.c |   30 ++++++++++--------------------
10  1 files changed, 10 insertions(+), 20 deletions(-)
11
12 diff --git a/notmuch-new.c b/notmuch-new.c
13 index 11fad8c..c5f841a 100644
14 --- a/notmuch-new.c
15 +++ b/notmuch-new.c
16 @@ -308,36 +308,26 @@ add_files (notmuch_database_t *notmuch,
17  static void
18  count_files (const char *path, int *count)
19  {
20 -    DIR *dir;
21 -    struct dirent *e, *entry = NULL;
22 -    int entry_length;
23 -    int err;
24 +    struct dirent *entry = NULL;
25      char *next;
26      struct stat st;
27 +    struct dirent **namelist = NULL;
28  
29 -    dir = opendir (path);
30 +    int n_entries= scandir(path, &namelist, 0, ino_cmp);
31  
32 -    if (dir == NULL) {
33 +    if (n_entries == -1) {
34         fprintf (stderr, "Warning: failed to open directory %s: %s\n",
35                  path, strerror (errno));
36         goto DONE;
37      }
38  
39 -    entry_length = offsetof (struct dirent, d_name) +
40 -       pathconf (path, _PC_NAME_MAX) + 1;
41 -    entry = malloc (entry_length);
42 +    int i=0;
43  
44      while (!interrupted) {
45 -       err = readdir_r (dir, entry, &e);
46 -       if (err) {
47 -           fprintf (stderr, "Error reading directory: %s\n",
48 -                    strerror (errno));
49 -           free (entry);
50 -           goto DONE;
51 -       }
52 +        if (i == n_entries)
53 +            break;
54  
55 -       if (e == NULL)
56 -           break;
57 +        entry= namelist[i++];
58  
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)
62    DONE:
63      if (entry)
64         free (entry);
65 -
66 -    closedir (dir);
67 +    if (namelist)
68 +        free (namelist);
69  }
70  
71  int
72 -- 
73 1.6.3.3
74
75