Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B0EF3431FBC for ; Tue, 17 Nov 2009 18:22:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o-waKGygo4MD for ; Tue, 17 Nov 2009 18:22:25 -0800 (PST) Received: from kaylee.flamingspork.com (kaylee.flamingspork.com [74.207.245.61]) by olra.theworths.org (Postfix) with ESMTP id 1AEA9431FAE for ; Tue, 17 Nov 2009 18:22:25 -0800 (PST) Received: from willster (localhost [127.0.0.1]) by kaylee.flamingspork.com (Postfix) with ESMTPS id 9B6F46333; Wed, 18 Nov 2009 02:22:02 +0000 (UTC) Received: by willster (Postfix, from userid 1000) id 0029810F5D92; Wed, 18 Nov 2009 13:22:21 +1100 (EST) From: Stewart Smith To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 13:22:20 +1100 Message-Id: <1258510940-7018-1-git-send-email-stewart@flamingspork.com> X-Mailer: git-send-email 1.6.3.3 Subject: [notmuch] [PATCH] count_files: sort directory in inode order before statting X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Nov 2009 02:22:25 -0000 --- notmuch-new.c | 30 ++++++++++-------------------- 1 files changed, 10 insertions(+), 20 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 11fad8c..c5f841a 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -308,36 +308,26 @@ add_files (notmuch_database_t *notmuch, static void count_files (const char *path, int *count) { - DIR *dir; - struct dirent *e, *entry = NULL; - int entry_length; - int err; + struct dirent *entry = NULL; char *next; struct stat st; + struct dirent **namelist = NULL; - dir = opendir (path); + int n_entries= scandir(path, &namelist, 0, ino_cmp); - if (dir == NULL) { + if (n_entries == -1) { fprintf (stderr, "Warning: failed to open directory %s: %s\n", path, strerror (errno)); goto DONE; } - entry_length = offsetof (struct dirent, d_name) + - pathconf (path, _PC_NAME_MAX) + 1; - entry = malloc (entry_length); + int i=0; while (!interrupted) { - err = readdir_r (dir, entry, &e); - if (err) { - fprintf (stderr, "Error reading directory: %s\n", - strerror (errno)); - free (entry); - goto DONE; - } + if (i == n_entries) + break; - if (e == NULL) - break; + entry= namelist[i++]; /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory. @@ -376,8 +366,8 @@ count_files (const char *path, int *count) DONE: if (entry) free (entry); - - closedir (dir); + if (namelist) + free (namelist); } int -- 1.6.3.3