Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / a3 / c19278f6c7c1b6c823eb375785523e8256fcf3
1 Return-Path: <james@jameswestby.net>\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 38807431FBF\r
6         for <notmuch@notmuchmail.org>; Sun, 20 Dec 2009 10:03:00 -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 P5HV5whxHL7W for <notmuch@notmuchmail.org>;\r
11         Sun, 20 Dec 2009 10:02:56 -0800 (PST)\r
12 Received: from jameswestby.net (jameswestby.net [89.145.97.141])\r
13         by olra.theworths.org (Postfix) with ESMTP id 9D8F5431FAE\r
14         for <notmuch@notmuchmail.org>; Sun, 20 Dec 2009 10:02:56 -0800 (PST)\r
15 Received: from cpc4-aztw22-2-0-cust59.aztw.cable.virginmedia.com\r
16         ([94.169.116.60] helo=flash)\r
17         by jameswestby.net with esmtpa (Exim 4.69)\r
18         (envelope-from <james@jameswestby.net>)\r
19         id 1NMQ7K-0000Rc-N7; Sun, 20 Dec 2009 18:02:54 +0000\r
20 Received: by flash (Postfix, from userid 1000)\r
21         id AF70B6E546A; Sun, 20 Dec 2009 18:02:48 +0000 (GMT)\r
22 From: James Westby <jw+debian@jameswestby.net>\r
23 To: notmuch@notmuchmail.org\r
24 Date: Sun, 20 Dec 2009 18:02:47 +0000\r
25 Message-Id: <1261332167-17994-1-git-send-email-jw+debian@jameswestby.net>\r
26 X-Mailer: git-send-email 1.6.3.3\r
27 In-Reply-To: <1261315232-21494-1-git-send-email-tom@dbservice.com>\r
28 References: <1261315232-21494-1-git-send-email-tom@dbservice.com>\r
29 Subject: [notmuch] [PATCH] Solaris doesn't have 'struct dirent::d_type'\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.12\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Sun, 20 Dec 2009 18:03:00 -0000\r
43 \r
44 From: Tomas Carnecky <tom@dbservice.com>\r
45 \r
46 Use stat(2) instead.\r
47 \r
48 Signed-off-by: Tomas Carnecky <tom@dbservice.com>\r
49 Signed-off-by: James Westby <jw+debian@jameswestby.net>\r
50 ---\r
51 \r
52   The original patch duplicated asprintf and stat calls, rearraging\r
53   the code means we don't need to.\r
54 \r
55   I have a concern about the duplicated stats in is_maildir, but they\r
56   are not so easy to save. I ran a quick timing test (3931 files), dropping\r
57   caches before each set:\r
58 \r
59     master:\r
60       real  2m3.545s\r
61       real  1m34.571s\r
62       real  1m36.005s\r
63 \r
64     original patch:\r
65       real  2m18.114s\r
66       real  1m34.843s\r
67       real  1m36.317s\r
68 \r
69     revised patch:\r
70       real  2m5.890s\r
71       real  1m36.387s\r
72       real  1m36.453s\r
73 \r
74   This shoes there is little impact of the code, but given that it is\r
75   around one percent we may want to make it conditional on platform\r
76   and save the extra stat calls.\r
77 \r
78   Thanks,\r
79 \r
80   James\r
81 \r
82  notmuch-new.c |   46 ++++++++++++++++++++++++++--------------------\r
83  1 files changed, 26 insertions(+), 20 deletions(-)\r
84 \r
85 diff --git a/notmuch-new.c b/notmuch-new.c\r
86 index 9d20616..c6f4963 100644\r
87 --- a/notmuch-new.c\r
88 +++ b/notmuch-new.c\r
89 @@ -90,12 +90,18 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b)\r
90   * Return 1 if the directory looks like a Maildir and 0 otherwise.\r
91   */\r
92  static int\r
93 -is_maildir (struct dirent **entries, int count)\r
94 +is_maildir (const char *path, struct dirent **entries, int count)\r
95  {\r
96      int i, found = 0;\r
97  \r
98      for (i = 0; i < count; i++) {\r
99 -       if (entries[i]->d_type != DT_DIR) continue;\r
100 +       char pbuf[PATH_MAX];\r
101 +        snprintf(pbuf, PATH_MAX, "%s/%s", path, entries[i]->d_name);\r
102 +\r
103 +       struct stat buf;\r
104 +       if (stat(pbuf, &buf) == -1 || !S_ISDIR(buf.st_mode))\r
105 +           continue;\r
106 +\r
107         if (strcmp(entries[i]->d_name, "new") == 0 ||\r
108             strcmp(entries[i]->d_name, "cur") == 0 ||\r
109             strcmp(entries[i]->d_name, "tmp") == 0)\r
110 @@ -178,24 +184,6 @@ add_files_recursive (notmuch_database_t *notmuch,\r
111         /* If this directory hasn't been modified since the last\r
112          * add_files, then we only need to look further for\r
113          * sub-directories. */\r
114 -       if (path_mtime <= path_dbtime && entry->d_type == DT_REG)\r
115 -           continue;\r
116 -\r
117 -       /* Ignore special directories to avoid infinite recursion.\r
118 -        * Also ignore the .notmuch directory.\r
119 -        */\r
120 -       /* XXX: Eventually we'll want more sophistication to let the\r
121 -        * user specify files to be ignored. */\r
122 -       if (strcmp (entry->d_name, ".") == 0 ||\r
123 -           strcmp (entry->d_name, "..") == 0 ||\r
124 -           (entry->d_type == DT_DIR &&\r
125 -            (strcmp (entry->d_name, "tmp") == 0) &&\r
126 -            is_maildir (namelist, num_entries)) ||\r
127 -           strcmp (entry->d_name, ".notmuch") ==0)\r
128 -       {\r
129 -           continue;\r
130 -       }\r
131 -\r
132         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
133  \r
134         if (stat (next, st)) {\r
135 @@ -216,6 +204,24 @@ add_files_recursive (notmuch_database_t *notmuch,\r
136             goto DONE;\r
137         }\r
138  \r
139 +       if (path_mtime <= path_dbtime && S_ISREG(st->st_mode))\r
140 +           continue;\r
141 +\r
142 +       /* Ignore special directories to avoid infinite recursion.\r
143 +        * Also ignore the .notmuch directory.\r
144 +        */\r
145 +       /* XXX: Eventually we'll want more sophistication to let the\r
146 +        * user specify files to be ignored. */\r
147 +       if (strcmp (entry->d_name, ".") == 0 ||\r
148 +           strcmp (entry->d_name, "..") == 0 ||\r
149 +           (S_ISDIR(st->st_mode) &&\r
150 +            (strcmp (entry->d_name, "tmp") == 0) &&\r
151 +            is_maildir (path, namelist, num_entries)) ||\r
152 +           strcmp (entry->d_name, ".notmuch") ==0)\r
153 +       {\r
154 +           continue;\r
155 +       }\r
156 +\r
157         if (S_ISREG (st->st_mode)) {\r
158             /* If the file hasn't been modified since the last\r
159              * add_files, then we need not look at it. */\r
160 -- \r
161 1.6.3.3\r
162 \r