unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Peter Wang <novalazy@gmail.com>
To: David Bremner <david@tethera.net>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH v4 06/12] test: add tests for insert
Date: Sat, 30 Mar 2013 15:05:37 +1100	[thread overview]
Message-ID: <20130330150537.GA1971@hili.localdomain> (raw)
In-Reply-To: <87d2uhiwoz.fsf@maritornes.cs.unb.ca>

On Fri, 29 Mar 2013 19:59:56 -0400, David Bremner <david@tethera.net> wrote:
> 
> It took longer than I thought (of course) but I finally finished looking
> at the first 6 patches. 
> 
> I already mentioned a minor man page issue in a seperate message.
> 
> I took a second pass through 03/12, and I think I would prefer thethe
> control flow of insert_message be closer to the standard style in
> notmuch of using a return value variable and a single cleanup block at
> the end.  Reasonable people can disagree about issues of style, but in
> the end consistency of the code base is also important.
> 
> d

static notmuch_bool_t
insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
		const char *dir, tag_op_list_t *tag_ops)
{
    char *tmppath;
    char *newpath;
    char *newdir;
    int fdout;
    char *cleanup_path;

    fdout = maildir_open_tmp_file (ctx, dir, &tmppath, &newpath, &newdir);
    if (fdout < 0)
	return FALSE;

    cleanup_path = tmppath;

    if (! copy_stdin (fdin, fdout))
	goto DONE;

    if (fsync (fdout) != 0) {
	fprintf (stderr, "Error: fsync failed: %s\n", strerror (errno));
	goto DONE;
    }

    close (fdout);
    fdout = -1;

    /* Atomically move the new message file from the Maildir 'tmp' directory
     * to the 'new' directory.  We follow the Dovecot recommendation to
     * simply use rename() instead of link() and unlink().
     * See also: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery
     */
    if (rename (tmppath, newpath) != 0) {
	fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno));
	goto DONE;
    }

    cleanup_path = newpath;

    if (! add_file_to_database (notmuch, newpath, tag_ops)) {
	/* XXX add an option to keep the file in maildir? */
	goto DONE;
    }

    if (! sync_dir (newdir))
	goto DONE;

    cleanup_path = NULL; /* success */

  DONE:
    if (fdout >= 0)
	close (fdout);

    if (cleanup_path) {
	unlink (cleanup_path);
	return FALSE;
    }

    return TRUE;
}

  reply	other threads:[~2013-03-30  4:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-24 12:07 [PATCH v4 00/12] insert command Peter Wang
2013-01-24 12:07 ` [PATCH v4 01/12] tag-util: move out 'tag' command-line checks Peter Wang
2013-03-31 10:00   ` Jani Nikula
2013-01-24 12:07 ` [PATCH v4 02/12] tag-util: do not reset list in parse_tag_command_line Peter Wang
2013-01-24 12:07 ` [PATCH v4 03/12] cli: add insert command Peter Wang
2013-03-06  1:13   ` David Bremner
2013-01-24 12:08 ` [PATCH v4 04/12] man: document 'insert' command Peter Wang
2013-03-29 23:25   ` David Bremner
2013-01-24 12:08 ` [PATCH v4 05/12] man: reference notmuch-insert.1 Peter Wang
2013-01-24 12:08 ` [PATCH v4 06/12] test: add tests for insert Peter Wang
2013-03-29 23:59   ` David Bremner
2013-03-30  4:05     ` Peter Wang [this message]
2013-04-01 19:38       ` Jani Nikula
2013-01-24 12:08 ` [PATCH v4 07/12] insert: add --folder option Peter Wang
2013-01-24 12:08 ` [PATCH v4 08/12] man: document insert " Peter Wang
2013-01-24 12:08 ` [PATCH v4 09/12] test: test " Peter Wang
2013-01-24 12:08 ` [PATCH v4 10/12] insert: add --create-folder option Peter Wang
2013-01-24 12:08 ` [PATCH v4 11/12] man: document insert --create-folder Peter Wang
2013-01-24 12:08 ` [PATCH v4 12/12] test: test insert --create-folder option Peter Wang

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=20130330150537.GA1971@hili.localdomain \
    --to=novalazy@gmail.com \
    --cc=david@tethera.net \
    --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).