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 AA597431FAF for ; Sat, 21 Apr 2012 21:27:55 -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 4rpea6IbBmzj for ; Sat, 21 Apr 2012 21:27:55 -0700 (PDT) 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 E7A53431FAE for ; Sat, 21 Apr 2012 21:27:54 -0700 (PDT) X-AuditID: 1209190f-b7f8a6d000000914-50-4f9388ca71a8 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id D8.A8.02324.AC8839F4; Sun, 22 Apr 2012 00:27:54 -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 q3M4RsB7006283; Sun, 22 Apr 2012 00:27:54 -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 q3M4Rr9T011058 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 22 Apr 2012 00:27:53 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1SLoOu-0003I9-Sr; Sun, 22 Apr 2012 00:27:52 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 2/4] new: Handle fatal errors in remove_filename and _remove_directory Date: Sun, 22 Apr 2012 00:27:46 -0400 Message-Id: <1335068868-12593-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1335068868-12593-1-git-send-email-amdragon@mit.edu> References: <1330357759-1337-1-git-send-email-amdragon@mit.edu> <1335068868-12593-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrHuqY7K/wZkbYhbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxvsJ29kKuiUrfhxrZW9gbBXpYuTgkBAwkTj606aLkRPIFJO4 cG89WxcjF4eQwD5GibUXFrBAOBsYJX4vWMwM4dxnkvj1bwkjSIuQwHxGiTNvBEBsNgENiW37 l4PFRQSkJXbenc0KsoFZQE3iT5cKSFhYIFJiwoltYGEWAVWJ4ytZQcK8Ag4Sa04eZII4QkHi 2brjYDangKPE4pfHoTaVSTS9XMY4gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0TvdzM Er3UlNJNjOCAkeTfwfjtoNIhRgEORiUe3lcmk/2FWBPLiitzDzFKcjApifLqVwKF+JLyUyoz Eosz4otKc1KLDzFKcDArifB+FgHK8aYkVlalFuXDpKQ5WJTEedW03vkJCaQnlqRmp6YWpBbB ZGU4OJQkeBPagBoFi1LTUyvSMnNKENJMHJwgw3mAhj9vBxleXJCYW5yZDpE/xagoJc6bD9Is AJLIKM2D64VF9CtGcaBXhHkFQKp4gMkArvsV0GAmoMEJMZNABpckIqSkGhiDTuQYO08wWS2S 9k4z7EjlxO3LmhfwfBRTM7KxOVweGPE/pWxOvY5P9kWbG8yxpicrg6XL35m9MS9feO6793Mj nvTw/VYzWd2ustTuOfeoOer/7J06q3Kiwh223do2Oev3JKZfTR4c22P3qoqdbU5WnDjhzYlH i1uUvq7PjprDcvXe9sPn195TYinOSDTUYi4qTgQAMpDAmMMCAAA= 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: Sun, 22 Apr 2012 04:27:55 -0000 Previously such errors were simply ignored. Now they cause an immediate cleanup and abort. --- notmuch-new.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 15c0b36..92e0489 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -785,8 +785,10 @@ remove_filename (notmuch_database_t *notmuch, add_files_state->renamed_messages++; if (add_files_state->synchronize_flags == TRUE) notmuch_message_maildir_flags_to_tags (message); - } else + status = NOTMUCH_STATUS_SUCCESS; + } else if (status == NOTMUCH_STATUS_SUCCESS) { add_files_state->removed_messages++; + } notmuch_message_destroy (message); notmuch_database_end_atomic (notmuch); return status; @@ -794,12 +796,13 @@ remove_filename (notmuch_database_t *notmuch, /* Recursively remove all filenames from the database referring to * 'path' (or to any of its children). */ -static void +static notmuch_status_t _remove_directory (void *ctx, notmuch_database_t *notmuch, const char *path, add_files_state_t *add_files_state) { + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; notmuch_directory_t *directory; notmuch_filenames_t *files, *subdirs; char *absolute; @@ -812,8 +815,10 @@ _remove_directory (void *ctx, { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (files)); - remove_filename (notmuch, absolute, add_files_state); + status = remove_filename (notmuch, absolute, add_files_state); talloc_free (absolute); + if (status) + goto DONE; } for (subdirs = notmuch_directory_get_child_directories (directory); @@ -822,11 +827,15 @@ _remove_directory (void *ctx, { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (subdirs)); - _remove_directory (ctx, notmuch, absolute, add_files_state); + status = _remove_directory (ctx, notmuch, absolute, add_files_state); talloc_free (absolute); + if (status) + goto DONE; } + DONE: notmuch_directory_destroy (directory); + return NOTMUCH_STATUS_SUCCESS; } int @@ -944,7 +953,9 @@ 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) { - remove_filename (notmuch, f->filename, &add_files_state); + ret = remove_filename (notmuch, f->filename, &add_files_state); + if (ret) + goto DONE; if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "messages", @@ -955,7 +966,9 @@ 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, &add_files_state); + ret = _remove_directory (ctx, notmuch, f->filename, &add_files_state); + if (ret) + goto DONE; if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Cleaned up", "directories", -- 1.7.9.1