1 Return-Path: <tomc@caurea.org>
\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 C7EB94196F2
\r
6 for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 11:53:53 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\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 9wdXvOH33o7V for <notmuch@notmuchmail.org>;
\r
16 Tue, 13 Apr 2010 11:53:52 -0700 (PDT)
\r
17 Received: from scotch.caurea.org (ks311007.kimsufi.com [188.165.197.188])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 879D1431FC1
\r
19 for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 11:53:52 -0700 (PDT)
\r
20 Received: by scotch.caurea.org (Postfix, from userid 101)
\r
21 id 9FE9012B8C0; Tue, 13 Apr 2010 20:54:05 +0200 (CEST)
\r
22 From: Tomas Carnecky <tom@dbservice.com>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH] Use wrapper functions to find the type of struct dirent
\r
25 Date: Tue, 13 Apr 2010 20:54:03 +0200
\r
26 Message-Id: <1271184843-3373-1-git-send-email-tom@dbservice.com>
\r
27 X-Mailer: git-send-email 1.7.0.5
\r
28 X-BeenThere: notmuch@notmuchmail.org
\r
29 X-Mailman-Version: 2.1.13
\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: Tue, 13 Apr 2010 18:53:53 -0000
\r
42 Some platforms don't provide DT_REG/DT_LNK/DT_DIR. Create wrapper functions
\r
43 which test the presence of those symbols and fall back to stat(2).
\r
46 Not sure if I got the handling of DT_UNKNOWN correct in all cases. Someone
\r
47 please double-check that.
\r
49 notmuch-new.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++------
\r
50 1 files changed, 62 insertions(+), 8 deletions(-)
\r
52 diff --git a/notmuch-new.c b/notmuch-new.c
\r
53 index 44b50aa..95ddddb 100644
\r
56 @@ -140,6 +140,62 @@ dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
\r
57 return strcmp ((*a)->d_name, (*b)->d_name);
\r
60 +/* Helper functions to test if a given dirent is of a certain type
\r
63 +_is_reg(const char *path, struct dirent *entry)
\r
66 + if (entry->d_type == DT_REG)
\r
70 + char buffer[PATH_MAX];
\r
71 + snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name);
\r
74 + if (!stat(buffer, &sbuf))
\r
75 + return S_ISREG(sbuf.st_mode);
\r
81 +_is_dir(const char *path, struct dirent *entry)
\r
84 + if (entry->d_type == DT_DIR)
\r
88 + char buffer[PATH_MAX];
\r
89 + snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name);
\r
92 + if (!stat(buffer, &sbuf))
\r
93 + return S_ISDIR(sbuf.st_mode);
\r
99 +_is_lnk(const char *path, struct dirent *entry)
\r
102 + if (entry->d_type == DT_LNK)
\r
106 + char buffer[PATH_MAX];
\r
107 + snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name);
\r
109 + struct stat sbuf;
\r
110 + if (!stat(buffer, &sbuf))
\r
111 + return S_ISLNK(sbuf.st_mode);
\r
116 /* Test if the directory looks like a Maildir directory.
\r
118 * Search through the array of directory entries to see if we can find all
\r
119 @@ -148,12 +204,12 @@ dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
\r
120 * Return 1 if the directory looks like a Maildir and 0 otherwise.
\r
123 -_entries_resemble_maildir (struct dirent **entries, int count)
\r
124 +_entries_resemble_maildir (const char *path, struct dirent **entries, int count)
\r
128 for (i = 0; i < count; i++) {
\r
129 - if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
\r
130 + if (!_is_dir(path, entries[i]))
\r
133 if (strcmp(entries[i]->d_name, "new") == 0 ||
\r
134 @@ -265,7 +321,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
137 /* Pass 1: Recurse into all sub-directories. */
\r
138 - is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
\r
139 + is_maildir = _entries_resemble_maildir (path, fs_entries, num_fs_entries);
\r
141 for (i = 0; i < num_fs_entries; i++) {
\r
143 @@ -280,9 +336,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
144 * scandir results, then it might be a directory (and if not,
\r
145 * then we'll stat and return immediately in the next level of
\r
147 - if (entry->d_type != DT_DIR &&
\r
148 - entry->d_type != DT_LNK &&
\r
149 - entry->d_type != DT_UNKNOWN)
\r
150 + if (!_is_dir(path, entry) && !_is_lnk(path, entry))
\r
154 @@ -360,7 +414,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
156 * In either case, a stat does the trick.
\r
158 - if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
\r
159 + if (_is_lnk(path, entry)) {
\r
162 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
163 @@ -376,7 +430,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
165 if (! S_ISREG (st.st_mode))
\r
167 - } else if (entry->d_type != DT_REG) {
\r
168 + } else if (!_is_reg(path, entry)) {
\r