--- /dev/null
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id DB508431FBF\r
+ for <notmuch@notmuchmail.org>; Fri, 29 Mar 2013 21:05:48 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id DLc2miKho1gI for <notmuch@notmuchmail.org>;\r
+ Fri, 29 Mar 2013 21:05:47 -0700 (PDT)\r
+Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com\r
+ [209.85.160.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 30559431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 29 Mar 2013 21:05:47 -0700 (PDT)\r
+Received: by mail-pb0-f46.google.com with SMTP id uo1so466022pbc.19\r
+ for <notmuch@notmuchmail.org>; Fri, 29 Mar 2013 21:05:46 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=x-received:date:message-id:from:to:cc:subject:in-reply-to\r
+ :references:mime-version:content-type:content-disposition\r
+ :content-transfer-encoding;\r
+ bh=kBdJMcqN4jyHv3ofBp/QHxfPJP5r0xdID49+jxrIOUw=;\r
+ b=U7TNoeA8azTB/KIhdBS1OXzko2m/iAnqyLBey4fhl160i2FUZUKaboqkEKLrHUeYua\r
+ APAHCT2qIHcHAuDS0Oa2fJ9+QnkKVvg6zyxg26QXxP18/BcfSBGcSHMQZY7u8+y+Eh0j\r
+ OCBX7Vm7o6H9XrntpbHffgvD3UddxDma19z1JDqi4ijbHLzvcb42JhWM4QSCq9aYDvEY\r
+ Ff5ClEediXLjJCF4PEYIxVvdJ2HULjpvgCrL0abm5oMWw/kEzBFXfKoSte8TyJqXBLZl\r
+ m4W3V3ASdPGJjJJ35ll52bKOlmZ1tzznvfdLVoxUwlfMynFBL5OXVRGTfZZvYXrZbv6w\r
+ Rm5g==\r
+X-Received: by 10.66.164.41 with SMTP id yn9mr7671130pab.93.1364616346320;\r
+ Fri, 29 Mar 2013 21:05:46 -0700 (PDT)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215])\r
+ by mx.google.com with ESMTPS id ve7sm5816598pab.11.2013.03.29.21.05.43\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Fri, 29 Mar 2013 21:05:45 -0700 (PDT)\r
+Date: Sat, 30 Mar 2013 15:05:37 +1100\r
+Message-ID: <20130330150537.GA1971@hili.localdomain>\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: David Bremner <david@tethera.net>\r
+Subject: Re: [PATCH v4 06/12] test: add tests for insert\r
+In-Reply-To: <87d2uhiwoz.fsf@maritornes.cs.unb.ca>\r
+References: <1359029288-12132-1-git-send-email-novalazy@gmail.com>\r
+ <1359029288-12132-7-git-send-email-novalazy@gmail.com>\r
+ <87d2uhiwoz.fsf@maritornes.cs.unb.ca>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 30 Mar 2013 04:05:49 -0000\r
+\r
+On Fri, 29 Mar 2013 19:59:56 -0400, David Bremner <david@tethera.net> wrote:\r
+> \r
+> It took longer than I thought (of course) but I finally finished looking\r
+> at the first 6 patches. \r
+> \r
+> I already mentioned a minor man page issue in a seperate message.\r
+> \r
+> I took a second pass through 03/12, and I think I would prefer thethe\r
+> control flow of insert_message be closer to the standard style in\r
+> notmuch of using a return value variable and a single cleanup block at\r
+> the end. Reasonable people can disagree about issues of style, but in\r
+> the end consistency of the code base is also important.\r
+> \r
+> d\r
+\r
+static notmuch_bool_t\r
+insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+ const char *dir, tag_op_list_t *tag_ops)\r
+{\r
+ char *tmppath;\r
+ char *newpath;\r
+ char *newdir;\r
+ int fdout;\r
+ char *cleanup_path;\r
+\r
+ fdout = maildir_open_tmp_file (ctx, dir, &tmppath, &newpath, &newdir);\r
+ if (fdout < 0)\r
+ return FALSE;\r
+\r
+ cleanup_path = tmppath;\r
+\r
+ if (! copy_stdin (fdin, fdout))\r
+ goto DONE;\r
+\r
+ if (fsync (fdout) != 0) {\r
+ fprintf (stderr, "Error: fsync failed: %s\n", strerror (errno));\r
+ goto DONE;\r
+ }\r
+\r
+ close (fdout);\r
+ fdout = -1;\r
+\r
+ /* Atomically move the new message file from the Maildir 'tmp' directory\r
+ * to the 'new' directory. We follow the Dovecot recommendation to\r
+ * simply use rename() instead of link() and unlink().\r
+ * See also: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery\r
+ */\r
+ if (rename (tmppath, newpath) != 0) {\r
+ fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno));\r
+ goto DONE;\r
+ }\r
+\r
+ cleanup_path = newpath;\r
+\r
+ if (! add_file_to_database (notmuch, newpath, tag_ops)) {\r
+ /* XXX add an option to keep the file in maildir? */\r
+ goto DONE;\r
+ }\r
+\r
+ if (! sync_dir (newdir))\r
+ goto DONE;\r
+\r
+ cleanup_path = NULL; /* success */\r
+\r
+ DONE:\r
+ if (fdout >= 0)\r
+ close (fdout);\r
+\r
+ if (cleanup_path) {\r
+ unlink (cleanup_path);\r
+ return FALSE;\r
+ }\r
+\r
+ return TRUE;\r
+}\r