Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 78 / 87477c996cdee555d96c95359b83bc53010198
1 Return-Path: <stewart@flamingspork.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id B0EF3431FBC\r
6         for <notmuch@notmuchmail.org>; Tue, 17 Nov 2009 18:22:25 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id o-waKGygo4MD for <notmuch@notmuchmail.org>;\r
11         Tue, 17 Nov 2009 18:22:25 -0800 (PST)\r
12 Received: from kaylee.flamingspork.com (kaylee.flamingspork.com\r
13         [74.207.245.61])\r
14         by olra.theworths.org (Postfix) with ESMTP id 1AEA9431FAE\r
15         for <notmuch@notmuchmail.org>; Tue, 17 Nov 2009 18:22:25 -0800 (PST)\r
16 Received: from willster (localhost [127.0.0.1])\r
17         by kaylee.flamingspork.com (Postfix) with ESMTPS id 9B6F46333;\r
18         Wed, 18 Nov 2009 02:22:02 +0000 (UTC)\r
19 Received: by willster (Postfix, from userid 1000)\r
20         id 0029810F5D92; Wed, 18 Nov 2009 13:22:21 +1100 (EST)\r
21 From: Stewart Smith <stewart@flamingspork.com>\r
22 To: notmuch@notmuchmail.org\r
23 Date: Wed, 18 Nov 2009 13:22:20 +1100\r
24 Message-Id: <1258510940-7018-1-git-send-email-stewart@flamingspork.com>\r
25 X-Mailer: git-send-email 1.6.3.3\r
26 Subject: [notmuch] [PATCH] count_files: sort directory in inode order before\r
27         statting\r
28 X-BeenThere: notmuch@notmuchmail.org\r
29 X-Mailman-Version: 2.1.12\r
30 Precedence: list\r
31 List-Id: "Use and development of the notmuch mail system."\r
32         <notmuch.notmuchmail.org>\r
33 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
34         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
35 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
36 List-Post: <mailto:notmuch@notmuchmail.org>\r
37 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
38 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
40 X-List-Received-Date: Wed, 18 Nov 2009 02:22:25 -0000\r
41 \r
42 ---\r
43  notmuch-new.c |   30 ++++++++++--------------------\r
44  1 files changed, 10 insertions(+), 20 deletions(-)\r
45 \r
46 diff --git a/notmuch-new.c b/notmuch-new.c\r
47 index 11fad8c..c5f841a 100644\r
48 --- a/notmuch-new.c\r
49 +++ b/notmuch-new.c\r
50 @@ -308,36 +308,26 @@ add_files (notmuch_database_t *notmuch,\r
51  static void\r
52  count_files (const char *path, int *count)\r
53  {\r
54 -    DIR *dir;\r
55 -    struct dirent *e, *entry = NULL;\r
56 -    int entry_length;\r
57 -    int err;\r
58 +    struct dirent *entry = NULL;\r
59      char *next;\r
60      struct stat st;\r
61 +    struct dirent **namelist = NULL;\r
62  \r
63 -    dir = opendir (path);\r
64 +    int n_entries= scandir(path, &namelist, 0, ino_cmp);\r
65  \r
66 -    if (dir == NULL) {\r
67 +    if (n_entries == -1) {\r
68         fprintf (stderr, "Warning: failed to open directory %s: %s\n",\r
69                  path, strerror (errno));\r
70         goto DONE;\r
71      }\r
72  \r
73 -    entry_length = offsetof (struct dirent, d_name) +\r
74 -       pathconf (path, _PC_NAME_MAX) + 1;\r
75 -    entry = malloc (entry_length);\r
76 +    int i=0;\r
77  \r
78      while (!interrupted) {\r
79 -       err = readdir_r (dir, entry, &e);\r
80 -       if (err) {\r
81 -           fprintf (stderr, "Error reading directory: %s\n",\r
82 -                    strerror (errno));\r
83 -           free (entry);\r
84 -           goto DONE;\r
85 -       }\r
86 +        if (i == n_entries)\r
87 +            break;\r
88  \r
89 -       if (e == NULL)\r
90 -           break;\r
91 +        entry= namelist[i++];\r
92  \r
93         /* Ignore special directories to avoid infinite recursion.\r
94          * Also ignore the .notmuch directory.\r
95 @@ -376,8 +366,8 @@ count_files (const char *path, int *count)\r
96    DONE:\r
97      if (entry)\r
98         free (entry);\r
99 -\r
100 -    closedir (dir);\r
101 +    if (namelist)\r
102 +        free (namelist);\r
103  }\r
104  \r
105  int\r
106 -- \r
107 1.6.3.3\r
108 \r