--- /dev/null
+Return-Path: <jani@nikula.org>\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 61C3D431FBF\r
+ for <notmuch@notmuchmail.org>; Mon, 1 Apr 2013 12:38:09 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[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 ASc43MD-JSaF for <notmuch@notmuchmail.org>;\r
+ Mon, 1 Apr 2013 12:38:07 -0700 (PDT)\r
+Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com\r
+ [209.85.217.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 07F1A431FAE\r
+ for <notmuch@notmuchmail.org>; Mon, 1 Apr 2013 12:38:06 -0700 (PDT)\r
+Received: by mail-lb0-f182.google.com with SMTP id z13so2265488lbh.27\r
+ for <notmuch@notmuchmail.org>; Mon, 01 Apr 2013 12:38:05 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=x-received:from:to:cc:subject:in-reply-to:references:user-agent\r
+ :date:message-id:mime-version:content-type:x-gm-message-state;\r
+ bh=3WHwMNrTInsmxWpNB0YfF9ysF7kB8VOwCYl9cIJc0Lc=;\r
+ b=EdyUcttnlO521BjJiZFenoZnI2u+s99Co9DX/QS9dUQaP0Wtzeiqv1zQNrZKFPsfxR\r
+ ial6vSZ4BLZjJY/2P5mYbExomzt9yBFiKrhbrQqCE4r+odHjl43Ij6eTEwAkPSLCtMzv\r
+ xj2g/yDvQpNuB4N+Fs0E2FGff0jB9I+1StpfF6olld8DwpLqxeol6yqHTDFX0VdHrNCj\r
+ yvAyO01hBnzVaqQSxNQclATecHbSLSRmoIuI1RPv6pimWJuWhybguKoS9D3UY7QjSVih\r
+ QxAmd8nYfh2CrtzLwbyzzQ9okAlBgXXbs7Wpp/FGXuFYuCizqajTQYhzMBLHxzBlCims\r
+ DHUQ==\r
+X-Received: by 10.112.180.105 with SMTP id dn9mr6260468lbc.10.1364845085490;\r
+ Mon, 01 Apr 2013 12:38:05 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+ [80.223.81.27])\r
+ by mx.google.com with ESMTPS id c7sm2795312lbe.6.2013.04.01.12.38.03\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Mon, 01 Apr 2013 12:38:04 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Peter Wang <novalazy@gmail.com>, David Bremner <david@tethera.net>\r
+Subject: Re: [PATCH v4 06/12] test: add tests for insert\r
+In-Reply-To: <20130330150537.GA1971@hili.localdomain>\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
+ <20130330150537.GA1971@hili.localdomain>\r
+User-Agent: Notmuch/0.15.2+70~g2eeb96a (http://notmuchmail.org) Emacs/24.2.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Mon, 01 Apr 2013 22:38:02 +0300\r
+Message-ID: <87wqsmnisl.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-Gm-Message-State:\r
+ ALoCoQlG3y/LzKPrOUx5eu5Eheunc1ZyNPZt0hywh8mdI2jCBO4/NDGyGpTUSc2BmYX4zUViBfzc\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: Mon, 01 Apr 2013 19:38:09 -0000\r
+\r
+On Sat, 30 Mar 2013, Peter Wang <novalazy@gmail.com> wrote:\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
+I think sync_dir() was worse than insert_message() in this regard.\r
+\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
+Put the happy day return TRUE here, and don't bother with the above\r
+statement.\r
+\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
+Only have the return FALSE path here. You can unconditionally unlink\r
+(cleanup_path) too AFAICS.\r
+\r
+> }\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r