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 38807431FBF for ; Sun, 20 Dec 2009 10:03:00 -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 P5HV5whxHL7W for ; Sun, 20 Dec 2009 10:02:56 -0800 (PST) Received: from jameswestby.net (jameswestby.net [89.145.97.141]) by olra.theworths.org (Postfix) with ESMTP id 9D8F5431FAE for ; Sun, 20 Dec 2009 10:02:56 -0800 (PST) Received: from cpc4-aztw22-2-0-cust59.aztw.cable.virginmedia.com ([94.169.116.60] helo=flash) by jameswestby.net with esmtpa (Exim 4.69) (envelope-from ) id 1NMQ7K-0000Rc-N7; Sun, 20 Dec 2009 18:02:54 +0000 Received: by flash (Postfix, from userid 1000) id AF70B6E546A; Sun, 20 Dec 2009 18:02:48 +0000 (GMT) From: James Westby To: notmuch@notmuchmail.org Date: Sun, 20 Dec 2009 18:02:47 +0000 Message-Id: <1261332167-17994-1-git-send-email-jw+debian@jameswestby.net> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1261315232-21494-1-git-send-email-tom@dbservice.com> References: <1261315232-21494-1-git-send-email-tom@dbservice.com> Subject: [notmuch] [PATCH] Solaris doesn't have 'struct dirent::d_type' 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: Sun, 20 Dec 2009 18:03:00 -0000 From: Tomas Carnecky Use stat(2) instead. Signed-off-by: Tomas Carnecky Signed-off-by: James Westby --- The original patch duplicated asprintf and stat calls, rearraging the code means we don't need to. I have a concern about the duplicated stats in is_maildir, but they are not so easy to save. I ran a quick timing test (3931 files), dropping caches before each set: master: real 2m3.545s real 1m34.571s real 1m36.005s original patch: real 2m18.114s real 1m34.843s real 1m36.317s revised patch: real 2m5.890s real 1m36.387s real 1m36.453s This shoes there is little impact of the code, but given that it is around one percent we may want to make it conditional on platform and save the extra stat calls. Thanks, James notmuch-new.c | 46 ++++++++++++++++++++++++++-------------------- 1 files changed, 26 insertions(+), 20 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 9d20616..c6f4963 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -90,12 +90,18 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b) * Return 1 if the directory looks like a Maildir and 0 otherwise. */ static int -is_maildir (struct dirent **entries, int count) +is_maildir (const char *path, struct dirent **entries, int count) { int i, found = 0; for (i = 0; i < count; i++) { - if (entries[i]->d_type != DT_DIR) continue; + char pbuf[PATH_MAX]; + snprintf(pbuf, PATH_MAX, "%s/%s", path, entries[i]->d_name); + + struct stat buf; + if (stat(pbuf, &buf) == -1 || !S_ISDIR(buf.st_mode)) + continue; + if (strcmp(entries[i]->d_name, "new") == 0 || strcmp(entries[i]->d_name, "cur") == 0 || strcmp(entries[i]->d_name, "tmp") == 0) @@ -178,24 +184,6 @@ add_files_recursive (notmuch_database_t *notmuch, /* If this directory hasn't been modified since the last * add_files, then we only need to look further for * sub-directories. */ - if (path_mtime <= path_dbtime && entry->d_type == DT_REG) - continue; - - /* Ignore special directories to avoid infinite recursion. - * Also ignore the .notmuch directory. - */ - /* XXX: Eventually we'll want more sophistication to let the - * user specify files to be ignored. */ - if (strcmp (entry->d_name, ".") == 0 || - strcmp (entry->d_name, "..") == 0 || - (entry->d_type == DT_DIR && - (strcmp (entry->d_name, "tmp") == 0) && - is_maildir (namelist, num_entries)) || - strcmp (entry->d_name, ".notmuch") ==0) - { - continue; - } - next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); if (stat (next, st)) { @@ -216,6 +204,24 @@ add_files_recursive (notmuch_database_t *notmuch, goto DONE; } + if (path_mtime <= path_dbtime && S_ISREG(st->st_mode)) + continue; + + /* Ignore special directories to avoid infinite recursion. + * Also ignore the .notmuch directory. + */ + /* XXX: Eventually we'll want more sophistication to let the + * user specify files to be ignored. */ + if (strcmp (entry->d_name, ".") == 0 || + strcmp (entry->d_name, "..") == 0 || + (S_ISDIR(st->st_mode) && + (strcmp (entry->d_name, "tmp") == 0) && + is_maildir (path, namelist, num_entries)) || + strcmp (entry->d_name, ".notmuch") ==0) + { + continue; + } + if (S_ISREG (st->st_mode)) { /* If the file hasn't been modified since the last * add_files, then we need not look at it. */ -- 1.6.3.3