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