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 2473E429E23 for ; Thu, 17 Feb 2011 23:59:40 -0800 (PST) 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 lfrgXpE-wUEj for ; Thu, 17 Feb 2011 23:59:38 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 3D55A429E32 for ; Thu, 17 Feb 2011 23:59:30 -0800 (PST) X-AuditID: 1209190f-b7c1dae000000a2b-6c-4d5e26e27861 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with SMTP id 6C.42.02603.2E62E5D4; Fri, 18 Feb 2011 02:59:30 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p1I7xTUn027142; Fri, 18 Feb 2011 02:59:29 -0500 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p1I7xSXw001550 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 18 Feb 2011 02:59:29 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.72) (envelope-from ) id 1PqLFQ-0008LQ-Oq; Fri, 18 Feb 2011 02:59:28 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 08/10] new: Synchronize maildir flags eagerly. Date: Fri, 18 Feb 2011 02:58:58 -0500 Message-Id: <1298015940-31986-9-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1298015940-31986-1-git-send-email-amdragon@mit.edu> References: <1298015940-31986-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: AAAAARdyUy0= Cc: amdragon@mit.edu 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: Fri, 18 Feb 2011 07:59:40 -0000 Because flag synchronization is stateless, it can be performed at any time as long as it's guaranteed to be performed after any change to a message's filename list. Take advantage of this to synchronize tags immediately after a filename is added or removed while the message is still frozen. With this change, filename removal is atomic and the unsynchronized window for filename add is very short. --- notmuch-new.c | 57 +++++++++++++++++---------------------------------------- 1 files changed, 17 insertions(+), 40 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 56fe7b0..767722a 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -50,7 +50,6 @@ typedef struct { _filename_list_t *directory_mtimes; notmuch_bool_t synchronize_flags; - _filename_list_t *message_ids_to_sync; } add_files_state_t; static volatile sig_atomic_t do_print_progress = 0; @@ -439,11 +438,8 @@ add_files_recursive (notmuch_database_t *notmuch, break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: - /* Defer sync of maildir flags until after old filenames - * are removed in the case of a rename. */ if (state->synchronize_flags == TRUE) - _filename_list_add (state->message_ids_to_sync, - notmuch_message_get_message_id (message)); + notmuch_message_maildir_flags_to_tags (message); break; case NOTMUCH_STATUS_FILE_NOT_EMAIL: fprintf (stderr, "Note: Ignoring non-mail file: %s\n", @@ -696,18 +692,23 @@ static notmuch_status_t remove_file (notmuch_database_t *notmuch, const char *path, int *renamed_files, - int *removed_files) + int *removed_files, + add_files_state_t *state) { notmuch_status_t status; notmuch_message_t *message; message = notmuch_database_find_message_by_filename (notmuch, path); if (!message) return NOTMUCH_STATUS_SUCCESS; + notmuch_message_freeze (message); status = notmuch_message_remove_filename (message, path); - if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) + if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { (*renamed_files)++; - else + if (state->synchronize_flags == TRUE) + notmuch_message_maildir_flags_to_tags (message); + } else (*removed_files)++; + notmuch_message_thaw (message); notmuch_message_destroy (message); return status; } @@ -719,7 +720,8 @@ _remove_directory (void *ctx, notmuch_database_t *notmuch, const char *path, int *renamed_files, - int *removed_files) + int *removed_files, + add_files_state_t *state) { notmuch_directory_t *directory; notmuch_filenames_t *files, *subdirs; @@ -733,7 +735,7 @@ _remove_directory (void *ctx, { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (files)); - remove_file (notmuch, absolute, renamed_files, removed_files); + remove_file (notmuch, absolute, renamed_files, removed_files, state); talloc_free (absolute); } @@ -743,7 +745,8 @@ _remove_directory (void *ctx, { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (subdirs)); - _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files); + _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files, + state); talloc_free (absolute); } @@ -785,7 +788,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_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); dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch"); @@ -854,7 +856,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) renamed_files = 0; gettimeofday (&tv_start, NULL); for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) { - remove_file (notmuch, f->filename, &renamed_files, &removed_files); + remove_file (notmuch, f->filename, &renamed_files, &removed_files, + &add_files_state); if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "messages", @@ -866,7 +869,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) gettimeofday (&tv_start, NULL); for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) { _remove_directory (ctx, notmuch, f->filename, - &renamed_files, &removed_files); + &renamed_files, &removed_files, &add_files_state); if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "directories", @@ -888,32 +891,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) talloc_free (add_files_state.removed_directories); talloc_free (add_files_state.directory_mtimes); - /* Now that removals are done (hence the database is aware of all - * renames), we can synchronize maildir_flags to tags for all - * messages that had new filenames appear on this run. */ - gettimeofday (&tv_start, NULL); - if (add_files_state.synchronize_flags) { - _filename_node_t *node; - notmuch_message_t *message; - for (node = add_files_state.message_ids_to_sync->head, i = 0; - node; - node = node->next, i++) - { - message = notmuch_database_find_message (notmuch, node->filename); - notmuch_message_maildir_flags_to_tags (message); - notmuch_message_destroy (message); - if (do_print_progress) { - do_print_progress = 0; - generic_print_progress ( - "Synchronized tags for", "messages", - tv_start, i, add_files_state.message_ids_to_sync->count); - } - } - } - - talloc_free (add_files_state.message_ids_to_sync); - add_files_state.message_ids_to_sync = NULL; - if (timer_is_active) stop_progress_printing_timer (); -- 1.7.2.3