unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
Subject: Re: [PATCH 2/3] new: Handle fatal errors in remove_filename and _remove_directory
Date: Mon, 16 Apr 2012 17:02:37 +0100	[thread overview]
Message-ID: <87wr5f4qci.fsf@qmul.ac.uk> (raw)
In-Reply-To: <1330357759-1337-3-git-send-email-amdragon@mit.edu>

On Mon, 27 Feb 2012, Austin Clements <amdragon@MIT.EDU> 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?

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.

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",
> -- 
> 1.7.7.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

  reply	other threads:[~2012-04-16 16:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27 15:49 [PATCH 0/3] Fix some error handling in notmuch new Austin Clements
2012-02-27 15:49 ` [PATCH 1/3] new: Consistently treat fatal errors as fatal Austin Clements
2012-04-16 15:53   ` Mark Walters
2012-04-22  4:11     ` Austin Clements
2012-02-27 15:49 ` [PATCH 2/3] new: Handle fatal errors in remove_filename and _remove_directory Austin Clements
2012-04-16 16:02   ` Mark Walters [this message]
2012-04-22  4:21     ` Austin Clements
2012-02-27 15:49 ` [PATCH 3/3] new: Print final fatal error message to stderr Austin Clements
2012-04-22  4:27 ` [PATCH v2 0/4] Fix some error handling in notmuch new Austin Clements
2012-04-22  4:27   ` [PATCH v2 1/4] new: Consistently treat fatal errors as fatal Austin Clements
2012-04-22  4:27   ` [PATCH v2 2/4] new: Handle fatal errors in remove_filename and _remove_directory Austin Clements
2012-04-22  7:34     ` Mark Walters
2012-04-22 15:36       ` Austin Clements
2012-04-22  4:27   ` [PATCH v2 3/4] new: Print final fatal error message to stderr Austin Clements
2012-04-22  4:27   ` [PATCH v2 4/4] new: Fix missing end_atomic in remove_filename on error Austin Clements
2012-04-22  7:42     ` Mark Walters
2012-04-22 15:50 ` [PATCH v3 0/4] Fix some error handling in notmuch new Austin Clements
2012-04-22 15:50   ` [PATCH v3 1/4] new: Consistently treat fatal errors as fatal Austin Clements
2012-04-25  2:28     ` David Bremner
2012-04-22 15:50   ` [PATCH v3 2/4] new: Handle fatal errors in remove_filename and _remove_directory Austin Clements
2012-04-22 15:50   ` [PATCH v3 3/4] new: Print final fatal error message to stderr Austin Clements
2012-04-22 15:50   ` [PATCH v3 4/4] new: Fix missing end_atomic in remove_filename on error Austin Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wr5f4qci.fsf@qmul.ac.uk \
    --to=markwalters1009@gmail.com \
    --cc=amdragon@MIT.EDU \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).