Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 11 / 87f65d438d88f7079d5e368971639abc88c33e
1 Return-Path: <amdragon@mit.edu>\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 199B4431FAF\r
6         for <notmuch@notmuchmail.org>; Wed, 11 Apr 2012 12:36:14 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 0yjZUp1Ugt2q for <notmuch@notmuchmail.org>;\r
16         Wed, 11 Apr 2012 12:36:13 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 3F5CC431FAE\r
20         for <notmuch@notmuchmail.org>; Wed, 11 Apr 2012 12:36:13 -0700 (PDT)\r
21 X-AuditID: 12074425-b7f4a6d0000008e0-04-4f85dd2c59a8\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id A1.33.02272.C2DD58F4; Wed, 11 Apr 2012 15:36:12 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q3BJaB68025613; \r
27         Wed, 11 Apr 2012 15:36:11 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3BJa97I025836\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Wed, 11 Apr 2012 15:36:10 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1SI3Kr-0000q7-Kj; Wed, 11 Apr 2012 15:36:09 -0400\r
37 Date: Wed, 11 Apr 2012 15:36:09 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Vladimir.Marek@oracle.com\r
40 Subject: Re: [PATCH 2/4] dirent->d_type not available on Soalris\r
41 Message-ID: <20120411193609.GC13549@mit.edu>\r
42 References:\r
43  <CAMoJFUvHbSfXLTGKf2ZZnaLpLzZiHJ7W_ZUYZzm70n5mw4r1Kg@mail.gmail.com>\r
44         <1333989127-21523-1-git-send-email-Vladimir.Marek@oracle.com>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 Content-Disposition: inline\r
48 In-Reply-To: <1333989127-21523-1-git-send-email-Vladimir.Marek@oracle.com>\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFprFKsWRmVeSWpSXmKPExsUixG6noqtzt9XfoPONicX1mzOZLTpu72az\r
52         mHF+F4sDs8ezVbeYPT4+vcXisezoT8YA5igum5TUnMyy1CJ9uwSujKtz1jEVTFCqmLTrAXMD\r
53         4zGpLkZODgkBE4lzk3YzQdhiEhfurWfrYuTiEBLYxyhxdf1bJghnA6PEr/7JjBDOSSaJee2f\r
54         WCGcJYwSf//cBirj4GARUJWYdUwFZBSbgIbEtv3LGUFsEQFZif9TPoGtYBawk5j24hiYLSzg\r
55         IPHv0Sx2EJtXQEfixcdHUNsmMEqcPnQbKiEocXLmExaIZi2JG/9egu1iFpCWWP6PAyTMKeAl\r
56         8WX7cjYQW1RARWLKyW1sExiFZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW6\r
57         Fnq5mSV6qSmlmxjBwe6iuoNxwiGlQ4wCHIxKPLy7JrT6C7EmlhVX5h5ilORgUhLlXXcVKMSX\r
58         lJ9SmZFYnBFfVJqTWnyIUYKDWUmE12V2i78Qb0piZVVqUT5MSpqDRUmcV1PrnZ+QQHpiSWp2\r
59         ampBahFMVoaDQ0mC98QdoKGCRanpqRVpmTklCGkmDk6Q4TxAw5eD1PAWFyTmFmemQ+RPMepy\r
60         PD/Ue4VRiCUvPy9VSpx3OkiRAEhRRmke3BxYknrFKA70ljDvCpAqHmCCg5v0CmgJE9CSz5NB\r
61         PiguSURISTUwng9XyfqRwr/u1qE7n+8sr7v0Zq/SwkUBkjqZ8YrlD5Xmd7/jdvtUvtxnbvt3\r
62         95ORvDdvTFixWJrJeWdCnejMjnDGBfs/bL3EtDRuLZfQbIeUr/+zvTT+F3uuYl/IV8fdlma4\r
63         sGKq9IW28MIbDD1friudDVmlk78v13nm9S/24vcLmjzEl+8+rMRSnJFoqMVcVJwIADzy/Iwt        AwAA\r
64 Cc: notmuch@notmuchmail.org, Vladimir Marek <vlmarek@volny.cz>\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Wed, 11 Apr 2012 19:36:14 -0000\r
78 \r
79 Correct me if I'm mistaken, but d_name will only be a basename, so\r
80 your calls to stat will fail for files that are not in the current\r
81 directory.  I think in all of the situations you had to call stat, we\r
82 already construct the absolute path of the file (sometimes a little\r
83 later in the code, but it can easily be moved), so this should be easy\r
84 to fix.\r
85 \r
86 Rather than sprinkling portability code throughout notmuch-new, it\r
87 seems like it would be simpler if this logic were wrapped in a\r
88 separate function.  For example, something along the (completely\r
89 untested) lines of,\r
90 \r
91 static mode_t\r
92 dirent_type (const struct *entry, const char *abspath)\r
93 {\r
94     struct stat statbuf;\r
95 #ifdef _DIRENT_HAVE_D_TYPE\r
96     static const mode_t modes[] = {\r
97         [DT_BLK]  = S_IFBLK,\r
98         [DT_CHR]  = S_IFCHR,\r
99         [DT_DIR]  = S_IFDIR,\r
100         [DT_FIFO] = S_IFIFO,\r
101         [DT_LNK]  = S_IFLNK,\r
102         [DT_REG]  = S_IFREG,\r
103         [DT_SOCK] = S_IFSOCK\r
104     };\r
105     if (entry->d_type >= 0 && entry->d_type < sizeof(modes)/sizeof(modes[0]) &&\r
106         modes[entry->d_type])\r
107         return modes[entry->d_type];\r
108 #endif\r
109 \r
110     if (stat(abspath, &statbuf) == -1)\r
111         return -1;\r
112     return statbuf.st_mode & S_IFMT;\r
113 }\r
114 \r
115 This has the added benefit of correctly handling DT_UNKNOWN, which we\r
116 currently don't.\r
117 \r
118 Instead of taking the absolute path of the file, this could take the\r
119 absolute path of the containing directory and construct the full path\r
120 from that and d_name; that would probably be a nicer interface, but it\r
121 would be redundant computation.\r
122 \r
123 Quoth Vladimir.Marek@oracle.com on Apr 09 at  6:32 pm:\r
124 > From: Vladimir Marek <vlmarek@volny.cz>\r
125\r
126 > The inspiration was taken from similar issue in mutt:\r
127 > http://does-not-exist.org/mail-archives/mutt-dev/msg11290.html\r
128\r
129 > Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
130 > ---\r
131 >  notmuch-new.c |   28 ++++++++++++++++++++++++++++\r
132 >  1 files changed, 28 insertions(+), 0 deletions(-)\r
133\r
134 > diff --git a/notmuch-new.c b/notmuch-new.c\r
135 > index 4f13535..3d265bd 100644\r
136 > --- a/notmuch-new.c\r
137 > +++ b/notmuch-new.c\r
138 > @@ -21,6 +21,9 @@\r
139 >  #include "notmuch-client.h"\r
140 >  \r
141 >  #include <unistd.h>\r
142 > +#ifndef _DIRENT_HAVE_D_TYPE\r
143 > +#include <sys/types.h>\r
144 > +#endif\r
145 >  \r
146 >  typedef struct _filename_node {\r
147 >      char *filename;\r
148 > @@ -167,7 +170,14 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
149 >      int i, found = 0;\r
150 >  \r
151 >      for (i = 0; i < count; i++) {\r
152 > +#ifdef _DIRENT_HAVE_D_TYPE\r
153 >       if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)\r
154 > +#else\r
155 > +     struct stat statbuf;\r
156 > +     if (stat(entries[i]->d_name, &statbuf) == -1)\r
157 > +             continue;\r
158 > +     if (! S_ISDIR(statbuf.st_mode))\r
159 > +#endif\r
160 >           continue;\r
161 >  \r
162 >       if (strcmp(entries[i]->d_name, "new") == 0 ||\r
163 > @@ -258,6 +268,9 @@ add_files_recursive (notmuch_database_t *notmuch,\r
164 >      struct stat st;\r
165 >      notmuch_bool_t is_maildir, new_directory;\r
166 >      const char **tag;\r
167 > +#ifndef _DIRENT_HAVE_D_TYPE\r
168 > +    struct stat statbuf;\r
169 > +#endif\r
170 >  \r
171 >      if (stat (path, &st)) {\r
172 >       fprintf (stderr, "Error reading directory %s: %s\n",\r
173 > @@ -328,9 +341,16 @@ add_files_recursive (notmuch_database_t *notmuch,\r
174 >        * scandir results, then it might be a directory (and if not,\r
175 >        * then we'll stat and return immediately in the next level of\r
176 >        * recursion). */\r
177 > +#ifdef _DIRENT_HAVE_D_TYPE\r
178 >       if (entry->d_type != DT_DIR &&\r
179 >           entry->d_type != DT_LNK &&\r
180 >           entry->d_type != DT_UNKNOWN)\r
181 > +#else\r
182 > +     if (stat(entry->d_name, &statbuf) == -1)\r
183 > +             continue;\r
184 > +     if (!(statbuf.st_mode & S_IFDIR) &&\r
185 > +         !(statbuf.st_mode & S_IFLNK))\r
186 > +#endif\r
187 >       {\r
188 >           continue;\r
189 >       }\r
190 > @@ -427,7 +447,11 @@ add_files_recursive (notmuch_database_t *notmuch,\r
191 >        *\r
192 >        * In either case, a stat does the trick.\r
193 >        */\r
194 > +#ifdef _DIRENT_HAVE_D_TYPE\r
195 >       if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {\r
196 > +#else\r
197 > +     if (stat(entry->d_name, &statbuf) == -1 || statbuf.st_mode & S_IFLNK) {\r
198 > +#endif\r
199 >           int err;\r
200 >  \r
201 >           next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
202 > @@ -443,7 +467,11 @@ add_files_recursive (notmuch_database_t *notmuch,\r
203 >  \r
204 >           if (! S_ISREG (st.st_mode))\r
205 >               continue;\r
206 > +#ifdef _DIRENT_HAVE_D_TYPE\r
207 >       } else if (entry->d_type != DT_REG) {\r
208 > +#else\r
209 > +     } else if (statbuf.st_mode & S_IFREG) {\r
210 > +#endif\r
211 >           continue;\r
212 >       }\r
213 >  \r