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 D95B0431FBC for ; Sun, 10 Jan 2010 06:22:50 -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 uvPPXZ2C0OkF for ; Sun, 10 Jan 2010 06:22:49 -0800 (PST) Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi [195.197.172.111]) by olra.theworths.org (Postfix) with ESMTP id 61FD1431FAE for ; Sun, 10 Jan 2010 06:22:49 -0800 (PST) Received: from djcbsoftware.nl (a88-114-93-212.elisa-laajakaista.fi [88.114.93.212]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 060D42167BD for ; Sun, 10 Jan 2010 16:22:44 +0200 (EET) Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1]) by djcbsoftware.nl (Postfix) with ESMTP id 8D4FB39C598 for ; Sun, 10 Jan 2010 16:22:20 +0200 (EET) Date: Sun, 10 Jan 2010 16:22:20 +0200 Message-ID: <878wc69h0j.wl%djcb@djcbsoftware.nl> From: Dirk-Jan C. Binnema To: "notmuch@notmuchmail org" Mail-Reply-To: djcb@djcbsoftware.nl User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0 (HANACHIRUSATO) Organization: DJCBSoftware MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Subject: [notmuch] [PATCH] * notmuch-new.c: refactor and improve dirs-to-ignore a bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: djcb@djcbsoftware.nl 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, 10 Jan 2010 14:22:51 -0000 Below, an updated patch for the latest notmuch; this refractors the dir check a bit, and adds the useful feature of making 'notmuch new' ignore directories with a '.noindex'-file in them. Best wishes, Dirk. ---- [PATCH] * notmuch-new.c: refactor and improve dirs-to-ignore a bit add a new function ignore_dir_entry, which determines whether a dir entry should be ignored (not entered). dirs to ignore are: '.' and '..', '.notmuch' and 'nnmaildir' (the later from gnus). Also, ignore dirs that contain a file called '.noindex'; thus, we can tell not much not to consider e.g. dirs with spam messages. --- notmuch-new.c | 76 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 56 insertions(+), 20 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index b740ee2..d1526cd 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -169,6 +169,47 @@ _entries_resemble_maildir (struct dirent **entries, int count) return 0; } + +/* Ignore special directories to avoid infinite recursion. + * Also ignore the .notmuch directory and any "tmp" directory + * that appears within a maildir. + */ +static int +ignore_dir_entry (const char* path, struct dirent *entry) +{ + char noindex[4096]; /* any path will fit */ + + /* ignore everything starting with a dot; this covers hidden + * files, as well as special dir (. and ..), but also things like + * gnus .nnmaildir or .notmuch */ + + /* special handling for dot-dirs */ + if (entry->d_name[0] == '.') { + + /* ignore '.' and '..' */ + if (entry->d_name[1] == '\0' || + (entry->d_name[1] == '.' && entry->d_name[2] == '\0')) + return 1; + + if (entry->d_name[1] == 'n') { /* optimization */ + /* ignore notmuch, gnus special dirs (or such-named files) */ + if (strcmp (entry->d_name, ".notmuch") == 0 || + strcmp (entry->d_name, ".nnmaildir") == 0) + return 1; + } + } + + /* we also check if dir contains a file called '.noindex'; if so, + * we ignore this directory; alloca would be suitable here, if not + * for the portability. */ + snprintf (noindex, sizeof(noindex), "%s/%s/.noindex", path, entry->d_name); + if (access (noindex, F_OK) == 0) + return 1; + + return 0; /* don't ignore */ +} + + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -275,21 +316,18 @@ add_files_recursive (notmuch_database_t *notmuch, if (entry->d_type != DT_DIR && entry->d_type != DT_LNK) continue; + + /* ignore tmp Maildirs, for obvious reasons */ + if (is_maildir && strcmp (entry->d_name, "tmp") == 0) + continue; /* Ignore special directories to avoid infinite recursion. - * Also ignore the .notmuch directory and any "tmp" directory - * that appears within a maildir. + * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and + * the .notmuch and .nnmaildir directories. */ - /* 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 || - (is_maildir && strcmp (entry->d_name, "tmp") == 0) || - strcmp (entry->d_name, ".notmuch") ==0) - { + if (ignore_dir_entry (path, entry)) continue; - } - + next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); status = add_files_recursive (notmuch, next, state); if (status && ret == NOTMUCH_STATUS_SUCCESS) @@ -575,18 +613,16 @@ count_files (const char *path, int *count) entry = fs_entries[i++]; + /* Note: it seems we're missing the '_entries_resemble_maildir' check + * here */ + /* Ignore special directories to avoid infinite recursion. - * Also ignore the .notmuch directory. + * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and + * the .notmuch and .nnmaildir directories. */ - /* 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 || - strcmp (entry->d_name, ".notmuch") == 0) - { + if (ignore_dir_entry (path, entry)) continue; - } - + if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) { next = NULL; fprintf (stderr, "Error descending from %s to %s: Out of memory\n", -- 1.6.3.3 -- Dirk-Jan C. Binnema Helsinki, Finland e:djcb@djcbsoftware.nl w:www.djcbsoftware.nl pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C