1 Return-Path: <jani@nikula.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 arlo.cworth.org (Postfix) with ESMTP id 3207B6DE02C6
\r
6 for <notmuch@notmuchmail.org>; Fri, 15 Apr 2016 12:31:03 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
10 X-Spam-Score: -0.557
\r
12 X-Spam-Status: No, score=-0.557 tagged_above=-999 required=5 tests=[AWL=0.163,
\r
13 DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,
\r
14 RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled
\r
15 Received: from arlo.cworth.org ([127.0.0.1])
\r
16 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id 19pRkScxQ1N8 for <notmuch@notmuchmail.org>;
\r
18 Fri, 15 Apr 2016 12:30:55 -0700 (PDT)
\r
19 Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com
\r
20 [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id 15DFF6DE02C9 for
\r
21 <notmuch@notmuchmail.org>; Fri, 15 Apr 2016 12:30:44 -0700 (PDT)
\r
22 Received: by mail-wm0-f67.google.com with SMTP id a140so8599757wma.2
\r
23 for <notmuch@notmuchmail.org>; Fri, 15 Apr 2016 12:30:44 -0700 (PDT)
\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=nikula-org.20150623.gappssmtp.com; s=20150623;
\r
26 h=from:to:cc:subject:date:message-id:in-reply-to:references
\r
27 :in-reply-to:references;
\r
28 bh=IjAFeeLPjOVUzS/KPfOPJ+kDhtHgyR+uCtBOblUYM7A=;
\r
29 b=ni9Kv1zzdoOTsYaIIXmIs7NZE9DIxC7D1W5jfX8N8Wz4Nn4kG9qQPDA+pg7t7P9TXc
\r
30 rEbRhw9o5mOcE0mzLfATlz9dM96uHTvzQNc32KLCUr5NTXg3PwtWgPt2gs/8RmxO7sfs
\r
31 NNF9XOAXk6hIhLlSrr+8ZkObbHlB4z9i9M9UES1CvS9unsMcCb6sMYzinpPCuGZjjVZ4
\r
32 wf4eWAwa7hAMXO0SBt56cZe3vODxk038uFvRKK6EtsE3c27NNtsOFFB6B/7B2y8HenPk
\r
33 GU2iGtZOZS5RMbb1sw0/eWu070nrDxpnInjZ+aAddLd+ollmv4E4Fx5NT3e8+MSSOJvo
\r
35 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
36 d=1e100.net; s=20130820;
\r
37 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
38 :references:in-reply-to:references;
\r
39 bh=IjAFeeLPjOVUzS/KPfOPJ+kDhtHgyR+uCtBOblUYM7A=;
\r
40 b=i3ND83O5lWSb2a+Fa0mR564kXkoBf4IRNGTXSywIWQt7f/HJKvNir7NzVW2iZ4bUdU
\r
41 Iev0dDAyeEicjXqPlS76gELCBqMdh3HU7zhZy++GcSZZCAPFOTI/9SW9gVKwkXxJoyos
\r
42 9hanvG5T2TqS7UeL7ZFGqYEuQqwGEA+WnW0U6t41q1rKxyZpLa7ejouN5rqfPv1d1EPe
\r
43 Malu32havTn6frDnpw+RtqeIw+OxngvcFS6h99iMS9PDWiJIYBp+ArsSa0ih7Z7njTkV
\r
44 tyxRdQG+hjz8jl5iJ+WXfW9cyKk3f1YAFl9OPxRc+pPrURazE8z867sw5kQr98z3o5VZ
\r
47 AOPr4FVk90nbjxP3QhO+hNUtoWzJrJnsmetLCGwuk3fK6ossjEwCC08NKy17GHcX0RVQCw==
\r
48 X-Received: by 10.28.101.213 with SMTP id z204mr6376130wmb.22.1460748642753;
\r
49 Fri, 15 Apr 2016 12:30:42 -0700 (PDT)
\r
50 Received: from localhost (mobile-access-bcee7f-102.dhcp.inet.fi.
\r
52 by smtp.gmail.com with ESMTPSA id w75sm39823395wmw.4.2016.04.15.12.30.41
\r
53 (version=TLSv1/SSLv3 cipher=OTHER);
\r
54 Fri, 15 Apr 2016 12:30:42 -0700 (PDT)
\r
55 From: Jani Nikula <jani@nikula.org>
\r
56 To: notmuch@notmuchmail.org
\r
57 Subject: [RFC PATCH 5/5] cli: convert count_files to new scandir
\r
58 Date: Fri, 15 Apr 2016 22:29:19 +0300
\r
60 <6aa9bcd2ce29f185f68b06c4684c65d900fdb85d.1460748142.git.jani@nikula.org>
\r
61 X-Mailer: git-send-email 2.1.4
\r
62 In-Reply-To: <cover.1460748142.git.jani@nikula.org>
\r
63 References: <cover.1460748142.git.jani@nikula.org>
\r
64 In-Reply-To: <cover.1460748142.git.jani@nikula.org>
\r
65 References: <cover.1460748142.git.jani@nikula.org>
\r
66 X-BeenThere: notmuch@notmuchmail.org
\r
67 X-Mailman-Version: 2.1.20
\r
69 List-Id: "Use and development of the notmuch mail system."
\r
70 <notmuch.notmuchmail.org>
\r
71 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
74 List-Post: <mailto:notmuch@notmuchmail.org>
\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
76 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
77 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
78 X-List-Received-Date: Fri, 15 Apr 2016 19:31:03 -0000
\r
80 Makes sense to use similar code in both places.
\r
82 notmuch-new.c | 97 +++++++++++++++++++++++++++++++++++------------------------
\r
83 1 file changed, 58 insertions(+), 39 deletions(-)
\r
85 diff --git a/notmuch-new.c b/notmuch-new.c
\r
86 index 262895d466ae..966b89ca39a0 100644
\r
89 @@ -733,64 +733,83 @@ stop_progress_printing_timer (void)
\r
91 count_files (const char *path, int *count, add_files_state_t *state)
\r
93 - struct dirent *entry = NULL;
\r
95 - struct dirent **fs_entries = NULL;
\r
96 - int num_fs_entries = scandir (path, &fs_entries, 0, NULL);
\r
97 - int entry_type, i;
\r
98 + char **fs_files = NULL, **fs_subdirs = NULL;
\r
99 + int num_fs_files = 0, num_fs_subdirs = 0;
\r
101 + notmuch_bool_t is_maildir;
\r
102 + struct filter filter = {
\r
107 - if (num_fs_entries == -1) {
\r
108 + filter.entry_type = S_IFDIR;
\r
109 + num_fs_subdirs = scandirx (path, &fs_subdirs, filter_fn, NULL, &filter);
\r
110 + if (num_fs_subdirs == -1) {
\r
111 fprintf (stderr, "Warning: failed to open directory %s: %s\n",
\r
112 path, strerror (errno));
\r
116 - for (i = 0; i < num_fs_entries && ! interrupted; i++) {
\r
117 - entry = fs_entries[i];
\r
118 + is_maildir = _entries_resemble_maildir (fs_subdirs, num_fs_subdirs);
\r
120 + /* Recurse to subdirs. */
\r
121 + for (i = 0; i < num_fs_subdirs && !interrupted; i++) {
\r
122 + const char *name = fs_subdirs[i];
\r
125 - /* Ignore special directories to avoid infinite recursion.
\r
126 - * Also ignore the .notmuch directory and files/directories
\r
127 - * the user has configured to be ignored.
\r
129 + * Ignore the .notmuch directory and any "tmp" directory that
\r
130 + * appears within a maildir.
\r
132 - if (strcmp (entry->d_name, ".") == 0 ||
\r
133 - strcmp (entry->d_name, "..") == 0 ||
\r
134 - strcmp (entry->d_name, ".notmuch") == 0 ||
\r
135 - _entry_in_ignore_list (entry->d_name, state))
\r
137 - if (state->debug && _entry_in_ignore_list (entry->d_name, state))
\r
138 - printf ("(D) count_files: explicitly ignoring %s/%s\n",
\r
141 + if ((is_maildir && strcmp (name, "tmp") == 0) ||
\r
142 + strcmp (name, ".notmuch") == 0)
\r
146 - if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
\r
148 + next = talloc_asprintf (NULL, "%s/%s", path, name);
\r
150 fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
\r
151 - path, entry->d_name);
\r
155 + count_files (next, count, state);
\r
156 + talloc_free (next);
\r
160 - entry_type = dirent_type (path, entry);
\r
161 - if (entry_type == S_IFREG) {
\r
162 - *count = *count + 1;
\r
163 - if (*count % 1000 == 0 && state->verbosity >= VERBOSITY_NORMAL) {
\r
164 - printf ("Found %d files so far.\r", *count);
\r
167 - } else if (entry_type == S_IFDIR) {
\r
168 - count_files (next, count, state);
\r
173 + filter.entry_type = S_IFREG;
\r
174 + num_fs_files = scandirx (path, &fs_files, filter_fn, NULL, &filter);
\r
175 + if (num_fs_files == -1) {
\r
176 + fprintf (stderr, "Warning: failed to open directory %s: %s\n",
\r
177 + path, strerror (errno));
\r
181 + if (state->verbosity >= VERBOSITY_NORMAL) {
\r
182 + int new_count = *count + num_fs_files;
\r
185 + if (new_count / 1000 > *count / 1000) {
\r
186 + printf ("Found %d files so far.\r", new_count / 1000 * 1000);
\r
191 + *count += num_fs_files;
\r
194 - if (fs_entries) {
\r
195 - for (i = 0; i < num_fs_entries; i++)
\r
196 - free (fs_entries[i]);
\r
197 + if (fs_subdirs) {
\r
198 + for (i = 0; i < num_fs_subdirs; i++)
\r
199 + free (fs_subdirs[i]);
\r
201 + free (fs_subdirs);
\r
204 + for (i = 0; i < num_fs_files; i++)
\r
205 + free (fs_files[i]);
\r
207 - free (fs_entries);
\r