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 C5B75431FAF for ; Sat, 21 Apr 2012 21:21:09 -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 KOAH1xXFdPbL for ; Sat, 21 Apr 2012 21:21:09 -0700 (PDT) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by olra.theworths.org (Postfix) with ESMTP id F06AB431FAE for ; Sat, 21 Apr 2012 21:21:08 -0700 (PDT) X-AuditID: 12074422-b7fd66d0000008f9-10-4f938733c3d6 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id E2.54.02297.337839F4; Sun, 22 Apr 2012 00:21:07 -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 q3M4L65m014648; Sun, 22 Apr 2012 00:21:07 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3M4L5ig010696 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 22 Apr 2012 00:21:06 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1SLoIL-0005S4-B7; Sun, 22 Apr 2012 00:21:05 -0400 Date: Sun, 22 Apr 2012 00:21:05 -0400 From: Austin Clements To: Mark Walters Subject: Re: [PATCH 2/3] new: Handle fatal errors in remove_filename and _remove_directory Message-ID: <20120422042105.GB17810@mit.edu> References: <1330357759-1337-1-git-send-email-amdragon@mit.edu> <1330357759-1337-3-git-send-email-amdragon@mit.edu> <87wr5f4qci.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wr5f4qci.fsf@qmul.ac.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hTV1jVun+xvsHeWlMXquTwW12/OZHZg 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mt5f3MFUMEWx4vSeRsYGxquSXYycHBICJhKr r6xjhLDFJC7cW8/WxcjFISSwj1Fiyul7LBDOBkaJv7duMYNUCQmcZJKYfUMSIrGEUWLa/l6w BIuAqsTU7e/ZQWw2AQ2JbfuXg40VEdCRuH1oAVicWUBa4tvvZiYQW1ggRmJxwwowmxeo5sSp 2YwQQycDDW06yQKREJQ4OfMJC0SzlsSNfy+BGjjABi3/xwES5gTatazrH1iJqICKxJST29gm MArNQtI9C0n3LITuBYzMqxhlU3KrdHMTM3OKU5N1i5MT8/JSi3RN9XIzS/RSU0o3MYLCmt1F aQfjz4NKhxgFOBiVeHhfmUz2F2JNLCuuzD3EKMnBpCTKq18JFOJLyk+pzEgszogvKs1JLT7E KMHBrCTC+1kEKMebklhZlVqUD5OS5mBREudV13rnJySQnliSmp2aWpBaBJOV4eBQkuBNaANq FCxKTU+tSMvMKUFIM3FwggznARruCFLDW1yQmFucmQ6RP8WoKCXOmw+SEABJZJTmwfXC0s4r RnGgV4R5fUGqeIApC677FdBgJqDBCTGTQAaXJCKkpBoYq1+vXe+X73fY9H7zj1vFCsUt4qIV e26oHt/m/0v62PO6kEl+mWlOuhfcl+w4znSypmgNl55znUzllh8zb9xuurDa4Hvz4sv3JjZl RPafilk3SUdMIlYnYj+Xm2ZBbmjhBLucyP3zvs2VOJzw+0Dv60Mlq5S2MZ9l1zy2/fyHZI7p gevlC1wblFiKMxINtZiLihMBN4SMshYDAAA= Cc: notmuch@notmuchmail.org 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:21:09 -0000 Quoth Mark Walters on Apr 16 at 5:02 pm: > On Mon, 27 Feb 2012, Austin Clements wrote: > > Previously such errors were simply ignored. Now they cause an > > immediate cleanup and abort. > > This one looks fine except for a minor query. > > > --- > > notmuch-new.c | 24 ++++++++++++++++++------ > > 1 files changed, 18 insertions(+), 6 deletions(-) > > > > diff --git a/notmuch-new.c b/notmuch-new.c > > index bd9786a..0cbd479 100644 > > --- a/notmuch-new.c > > +++ b/notmuch-new.c > > @@ -780,8 +780,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; > > @@ -789,12 +791,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_directory_t *directory; > > notmuch_filenames_t *files, *subdirs; > > char *absolute; > > @@ -807,8 +810,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) > > + return status; > > } > > > > for (subdirs = notmuch_directory_get_child_directories (directory); > > @@ -817,11 +822,14 @@ _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) > > + return status; > > } > > > > notmuch_directory_destroy (directory); > > + return NOTMUCH_STATUS_SUCCESS; > > } > > In the two "return status" lines above seem to mean we don't call > notmuch_directory_destroy. Does that matter? Good point. I've fixed this to use the usual goto DONE cleanup idiom. > The other query is not actually about this patch: just something that > came up when reading it. Should notmuch_database_begin_atomic and > notmuch_database_end_atomic always be paired? One of the (existing) > error cases in remove_filename seems to return without calling end. Yes, they should be. I've added a patch to fix that. > Best wishes > > Mark > > > int > > @@ -939,7 +947,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", > > @@ -950,7 +960,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",