From: Peter Wang Date: Sat, 30 Mar 2013 04:05:37 +0000 (+1100) Subject: Re: [PATCH v4 06/12] test: add tests for insert X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=c078e669e25b524f2494800e0a57ae8b6eeb6f6c;p=notmuch-archives.git Re: [PATCH v4 06/12] test: add tests for insert --- diff --git a/46/542d90f0302b7a09b675ca7a03fe06da0991d7 b/46/542d90f0302b7a09b675ca7a03fe06da0991d7 new file mode 100644 index 000000000..96657488a --- /dev/null +++ b/46/542d90f0302b7a09b675ca7a03fe06da0991d7 @@ -0,0 +1,145 @@ +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 DB508431FBF + for ; Fri, 29 Mar 2013 21:05:48 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, 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 DLc2miKho1gI for ; + Fri, 29 Mar 2013 21:05:47 -0700 (PDT) +Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com + [209.85.160.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 30559431FAE + for ; Fri, 29 Mar 2013 21:05:47 -0700 (PDT) +Received: by mail-pb0-f46.google.com with SMTP id uo1so466022pbc.19 + for ; Fri, 29 Mar 2013 21:05:46 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=x-received:date:message-id:from:to:cc:subject:in-reply-to + :references:mime-version:content-type:content-disposition + :content-transfer-encoding; + bh=kBdJMcqN4jyHv3ofBp/QHxfPJP5r0xdID49+jxrIOUw=; + b=U7TNoeA8azTB/KIhdBS1OXzko2m/iAnqyLBey4fhl160i2FUZUKaboqkEKLrHUeYua + APAHCT2qIHcHAuDS0Oa2fJ9+QnkKVvg6zyxg26QXxP18/BcfSBGcSHMQZY7u8+y+Eh0j + OCBX7Vm7o6H9XrntpbHffgvD3UddxDma19z1JDqi4ijbHLzvcb42JhWM4QSCq9aYDvEY + Ff5ClEediXLjJCF4PEYIxVvdJ2HULjpvgCrL0abm5oMWw/kEzBFXfKoSte8TyJqXBLZl + m4W3V3ASdPGJjJJ35ll52bKOlmZ1tzznvfdLVoxUwlfMynFBL5OXVRGTfZZvYXrZbv6w + Rm5g== +X-Received: by 10.66.164.41 with SMTP id yn9mr7671130pab.93.1364616346320; + Fri, 29 Mar 2013 21:05:46 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id ve7sm5816598pab.11.2013.03.29.21.05.43 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Fri, 29 Mar 2013 21:05:45 -0700 (PDT) +Date: Sat, 30 Mar 2013 15:05:37 +1100 +Message-ID: <20130330150537.GA1971@hili.localdomain> +From: Peter Wang +To: David Bremner +Subject: Re: [PATCH v4 06/12] test: add tests for insert +In-Reply-To: <87d2uhiwoz.fsf@maritornes.cs.unb.ca> +References: <1359029288-12132-1-git-send-email-novalazy@gmail.com> + <1359029288-12132-7-git-send-email-novalazy@gmail.com> + <87d2uhiwoz.fsf@maritornes.cs.unb.ca> +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +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: Sat, 30 Mar 2013 04:05:49 -0000 + +On Fri, 29 Mar 2013 19:59:56 -0400, David Bremner 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; +}