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 EB815429E2F for ; Tue, 13 Sep 2011 14:32:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled 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 fRRhN2pY-Px9 for ; Tue, 13 Sep 2011 14:32:28 -0700 (PDT) Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8AB1B429E29 for ; Tue, 13 Sep 2011 14:32:26 -0700 (PDT) Received: from localhost6.localdomain6 (entry3.nixu.fi [193.209.237.21]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p8DLW8G4022252; Wed, 14 Sep 2011 00:32:18 +0300 From: tomi.ollila@iki.fi To: notmuch@notmuchmail.org Subject: [PATCH 3/3] added support for user-specified directories to exclude Date: Wed, 14 Sep 2011 00:32:04 +0300 Message-Id: <1315949524-4948-4-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi> References: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi> Cc: Tomi Ollila X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Tue, 13 Sep 2011 21:32:31 -0000 From: Tomi Ollila A new configuration key 'database.exclude' is used to determine which directories user wants not to be scanned for new mails. --- notmuch-client.h | 3 +++ notmuch-config.c | 19 +++++++++++++++++++ notmuch-new.c | 22 ++++++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index b50cb38..503ac79 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -197,6 +197,9 @@ void notmuch_config_set_database_path (notmuch_config_t *config, const char *database_path); +const char ** +notmuch_config_get_database_exclude (notmuch_config_t *config, + size_t *length); const char * notmuch_config_get_user_name (notmuch_config_t *config); diff --git a/notmuch-config.c b/notmuch-config.c index 648639b..b628074 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -88,6 +88,8 @@ struct _notmuch_config { GKeyFile *key_file; char *database_path; + const char **database_exclude; + size_t database_exclude_length; char *user_name; char *user_primary_email; const char **user_other_email; @@ -282,6 +284,8 @@ notmuch_config_open (void *ctx, config->key_file = g_key_file_new (); config->database_path = NULL; + config->database_exclude = NULL; + config->database_exclude_length = 0; config->user_name = NULL; config->user_primary_email = NULL; config->user_other_email = NULL; @@ -502,6 +506,21 @@ notmuch_config_set_database_path (notmuch_config_t *config, config->database_path = NULL; } +const char ** +notmuch_config_get_database_exclude (notmuch_config_t *config, + size_t *length) +{ + if (config->database_exclude == NULL) { + config->database_exclude = notmuch_talloc_g_key_file_get_string_list( + config, + config->key_file, + "database", "exclude", + &config->database_exclude_length, NULL); + } + *length = config->database_exclude_length; + return config->database_exclude; +} + const char * notmuch_config_get_user_name (notmuch_config_t *config) { diff --git a/notmuch-new.c b/notmuch-new.c index 7d17793..36da15f 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -38,6 +38,8 @@ typedef struct { int verbose; const char **new_tags; size_t new_tags_length; + const char **database_exclude; + size_t database_exclude_length; int total_files; int processed_files; @@ -293,6 +295,8 @@ add_files_recursive (notmuch_database_t *notmuch, is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries); for (i = 0; i < num_fs_entries; i++) { + size_t j; + if (interrupted) break; @@ -316,8 +320,6 @@ add_files_recursive (notmuch_database_t *notmuch, * Also ignore the .notmuch directory and any "tmp" directory * that appears within a maildir. */ - /* 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) || @@ -325,6 +327,12 @@ add_files_recursive (notmuch_database_t *notmuch, { continue; } + /* Ignore user-specified directories */ + for (j = 0; j < state->database_exclude_length; j++) + if (strcmp(entry->d_name, state->database_exclude[j]) == 0) + break; + if (j < state->database_exclude_length) + continue; next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); status = add_files_recursive (notmuch, next, state); @@ -357,11 +365,20 @@ add_files_recursive (notmuch_database_t *notmuch, /* Pass 2: Scan for new files, removed files, and removed directories. */ for (i = 0; i < num_fs_entries; i++) { + size_t j; + if (interrupted) break; entry = fs_entries[i]; + /* Ignore user-specified files & directories */ + for (j = 0; j < state->database_exclude_length; j++) + if (strcmp(entry->d_name, state->database_exclude[j]) == 0) + break; + if (j < state->database_exclude_length) + continue; + /* Check if we've walked past any names in db_files or * db_subdirs. If so, these have been deleted. */ while (notmuch_filenames_valid (db_files) && @@ -800,6 +817,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) return 1; add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); + add_files_state.database_exclude = notmuch_config_get_database_exclude (config, &add_files_state.database_exclude_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); add_files_state.message_ids_to_sync = _filename_list_create (ctx); db_path = notmuch_config_get_database_path (config); -- 1.7.3.4