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 ADC8A431FB6 for ; Sun, 22 Apr 2012 08:50:59 -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 Gdl5Y9FMsNdb for ; Sun, 22 Apr 2012 08:50:58 -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 81EF8431FBD for ; Sun, 22 Apr 2012 08:50:58 -0700 (PDT) X-AuditID: 12074424-b7fae6d000000906-f4-4f9428e29453 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id 9D.8B.02310.2E8249F4; Sun, 22 Apr 2012 11:50:58 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q3MFovDI018620; Sun, 22 Apr 2012 11:50:57 -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 q3MFou1h003693 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 22 Apr 2012 11:50:57 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1SLz3w-0002fD-F0; Sun, 22 Apr 2012 11:50:56 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 2/4] new: Handle fatal errors in remove_filename and _remove_directory Date: Sun, 22 Apr 2012 11:50:50 -0400 Message-Id: <1335109852-10150-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1335109852-10150-1-git-send-email-amdragon@mit.edu> References: <1330357759-1337-1-git-send-email-amdragon@mit.edu> <1335109852-10150-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrftIY4q/wck9bBbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxrl1T5kKfktULDw+hbWB8atwFyMnh4SAicTv1m4WCFtM4sK9 9WxdjFwcQgL7GCU2Pr7HDuFsYJQ48PY3K4Rzn0li7bMJUGXzGSXWvXsO1s8moCGxbf9yRhBb REBaYufd2UAdHBzMAmoSf7pUQMLCApESFz7+ZQIJswioSrQ8CwcJ8wo4SNx50cEEcYWCxLN1 x8FsTgFHiY/vVoLZQgJlEt/mvWWfwMi/gJFhFaNsSm6Vbm5iZk5xarJucXJiXl5qka65Xm5m iV5qSukmRlDQsLuo7GBsPqR0iFGAg1GJh/eVyWR/IdbEsuLK3EOMkhxMSqK8bmpT/IX4kvJT KjMSizPii0pzUosPMUpwMCuJ8H4WASrnTUmsrEotyodJSXOwKInzami98xMSSE8sSc1OTS1I LYLJynBwKEnwmgOjQ0iwKDU9tSItM6cEIc3EwQkynAdouDVIDW9xQWJucWY6RP4Uo6KUOK8y SEIAJJFRmgfXC4vqV4ziQK8I84aAVPEAEwJc9yugwUxAgxNiJoEMLklESEk1MKZX2ZyedSIq pGWVlesC1SsB87d0ZJst6dibI6Bry/fv9M7Z7bOP7b8gub1K+fHF4IeMdT+lV0jP7/oxK/Bh WPNW0ydaBcdWBZyQurc3nt2sx5H1WvGVzNCG7JAvd5iWSYafZNx3vV3jkmbofEFesbUrBCyN esztRP8fu+zxSPUw07eKZXfik5RYijMSDbWYi4oTAWJL7HzFAgAA 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 15:51:00 -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..2faf2f8 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 status; } 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