From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 37740429E4B for ; Thu, 17 Feb 2011 23:59:38 -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 eOBg3Bak1+V1 for ; Thu, 17 Feb 2011 23:59:36 -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 71DFF429E23 for ; Thu, 17 Feb 2011 23:59:29 -0800 (PST) X-AuditID: 1209190f-b7c1dae000000a2b-69-4d5e26e1f1d8 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with SMTP id 4C.42.02603.1E62E5D4; Fri, 18 Feb 2011 02:59:29 -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 p1I7xSd2027140; Fri, 18 Feb 2011 02:59:28 -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 p1I7xRwU001547 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 18 Feb 2011 02:59:28 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.72) (envelope-from ) id 1PqLFP-0008LN-JY; Fri, 18 Feb 2011 02:59:27 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 07/10] new: Use the new filename removal API. Date: Fri, 18 Feb 2011 02:58:57 -0500 Message-Id: <1298015940-31986-8-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:38 -0000 This paves the way for eager tag synchronization and correct removal atomicity. --- notmuch-new.c | 35 +++++++++++++++++++++++------------ 1 files changed, 23 insertions(+), 12 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 65682d8..56fe7b0 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -691,6 +691,27 @@ upgrade_print_progress (void *closure, fflush (stdout); } +/* Remove one message filename from the database. */ +static notmuch_status_t +remove_file (notmuch_database_t *notmuch, + const char *path, + int *renamed_files, + int *removed_files) +{ + notmuch_status_t status; + notmuch_message_t *message; + message = notmuch_database_find_message_by_filename (notmuch, path); + if (!message) + return NOTMUCH_STATUS_SUCCESS; + status = notmuch_message_remove_filename (message, path); + if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) + (*renamed_files)++; + else + (*removed_files)++; + notmuch_message_destroy (message); + return status; +} + /* Recursively remove all filenames from the database referring to * 'path' (or to any of its children). */ static void @@ -702,7 +723,6 @@ _remove_directory (void *ctx, { notmuch_directory_t *directory; notmuch_filenames_t *files, *subdirs; - notmuch_status_t status; char *absolute; directory = notmuch_database_get_directory (notmuch, path); @@ -713,11 +733,7 @@ _remove_directory (void *ctx, { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (files)); - status = notmuch_database_remove_message (notmuch, absolute); - if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) - *renamed_files = *renamed_files + 1; - else - *removed_files = *removed_files + 1; + remove_file (notmuch, absolute, renamed_files, removed_files); talloc_free (absolute); } @@ -749,7 +765,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) struct sigaction action; _filename_node_t *f; int renamed_files, removed_files; - notmuch_status_t status; int i; notmuch_bool_t timer_is_active = FALSE; @@ -839,11 +854,7 @@ 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) { - status = notmuch_database_remove_message (notmuch, f->filename); - if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) - renamed_files++; - else - removed_files++; + remove_file (notmuch, f->filename, &renamed_files, &removed_files); if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "messages", -- 1.7.2.3