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 1994D429E2B for ; Sat, 11 Jun 2011 13:07:24 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 WRu40kZ59v2z for ; Sat, 11 Jun 2011 13:07:22 -0700 (PDT) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 0F7B7431FB6 for ; Sat, 11 Jun 2011 13:07:21 -0700 (PDT) X-AuditID: 12074424-b7bc6ae000005a77-73-4df3caf941fc Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id 2F.25.23159.9FAC3FD4; Sat, 11 Jun 2011 16:07:21 -0400 (EDT) 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 p5BK7LFv015082; Sat, 11 Jun 2011 16:07:21 -0400 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 p5BK7KVv006049 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 11 Jun 2011 16:07:21 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1QVUSm-0000Ib-8W; Sat, 11 Jun 2011 16:07:20 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 14/17] new: Cleanup. De-duplicate file name removal code. Date: Sat, 11 Jun 2011 16:04:40 -0400 Message-Id: <1307822683-848-15-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu> References: <87ei34rnc5.fsf@yoom.home.cworth.org> <1307822683-848-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCIsWRmVeSWpSXmKPExsUixCmqrPvz1Gdfg/ZDGhbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxr9X95kLropWvHi3j72B8YBgFyMHh4SAicTayWZdjJxAppjE hXvr2boYuTiEBPYxSkxo/coC4WxglPhweTdU5j6TRNPOK0wQznxGiZ2bX7OC9LMJaEhs27+c EcQWEZCW2Hl3NivICmYBNYk/XSogYWEBL4mVB9ewg9gsAqoSH749YAKxeQXsJRZOmcIGcYaC xJUr81hAbE6g+LyDV8FsIYE0iSW3drNPYORfwMiwilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdc LzezRC81pXQTIyho2F1UdjA2H1I6xCjAwajEw3tq1WdfIdbEsuLK3EOMkhxMSqK8OieAQnxJ +SmVGYnFGfFFpTmpxYcYJTiYlUR417d/8hXiTUmsrEotyodJSXOwKInzzpNU9xUSSE8sSc1O TS1ILYLJynBwKEnwSgKjQ0iwKDU9tSItM6cEIc3EwQkynAdo+NGTQDW8xQWJucWZ6RD5U4zG HI83bDrEyNG+GUgKseTl56VKifOqg4wTACnNKM2DmwaL/FeM4kDPCfP+ABnIA0wacPNeAa1i AlolUAq2qiQRISXVwLh/aaPe8s8zTn4pefBF4PLt1eEb+fJa50wOebzRyXfFolW+9a82nm5T 4NwVV761dP80sainrL9lDaZ3iohoSnx6+UZq1jfFczcue7dedbvCqWem4bephGvS3GcvghPq FtuXTL9v/T3+jODm4wobnj52qDGVbbvF2Mn480jGBhedrret155kca1SYinOSDTUYi4qTgQA 6anu1NcCAAA= Cc: Austin Clements 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: Sat, 11 Jun 2011 20:07:24 -0000 Previously, file name removal was implemented identically in two places. Now it's captured in one function. This is important because file name removal is about to get slightly more complicated with eager tag synchronization and correct removal atomicity. --- notmuch-new.c | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index cdc8a1c..dc349f6 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -696,6 +696,21 @@ upgrade_print_progress (void *closure, fflush (stdout); } +/* Remove one message filename from the database. */ +static notmuch_status_t +remove_filename (notmuch_database_t *notmuch, + const char *path, + add_files_state_t *add_files_state) +{ + notmuch_status_t status; + status = notmuch_database_remove_message (notmuch, path); + if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) + add_files_state->renamed_messages++; + else + add_files_state->removed_messages++; + return status; +} + /* Recursively remove all filenames from the database referring to * 'path' (or to any of its children). */ static void @@ -706,7 +721,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); @@ -717,11 +731,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) - add_files_state->renamed_messages++; - else - add_files_state->removed_messages++; + remove_filename (notmuch, absolute, add_files_state); talloc_free (absolute); } @@ -752,7 +762,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) char *dot_notmuch_path; struct sigaction action; _filename_node_t *f; - notmuch_status_t status; int i; notmuch_bool_t timer_is_active = FALSE; @@ -841,11 +850,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) 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) - add_files_state.renamed_messages++; - else - add_files_state.removed_messages++; + remove_filename (notmuch, f->filename, &add_files_state); if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "messages", -- 1.7.5.1