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 C5EE9431FDA for ; Wed, 25 Jul 2012 06:43:39 -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 jZeWDMRInm03 for ; Wed, 25 Jul 2012 06:43:38 -0700 (PDT) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8F377431FC7 for ; Wed, 25 Jul 2012 06:43:38 -0700 (PDT) Received: by mail-pb0-f53.google.com with SMTP id rr13so1767731pbb.26 for ; Wed, 25 Jul 2012 06:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5KHtITWrLCO0ratQQ+WrdIQzSEdNXhxkwJR4kQ3IYXQ=; b=NUJbeJUvfkUYAGIp6onbf3+X1+L9GEsk9jnZtndcvzOLGC62X90+xQttetwcxE6aJa u+p5swPreCh7u/PNZcPry/VRzH7w7LcpgcXDLduCxBEhhYpByLrtIX/TgWydmz+TeFu0 0icVL6wNtyUmmV7qNnJx2epqzGDMHVMkgUj75vIviZp8DtAIJo55gzzVrMRqK6e4qPr3 FI9dwPRj3GRGfKZBILAUkDRUlPaoGXHSRUVfQSwY1s6yNEyxCF5l/RXQ+iXYrMyNJnLF 5Om/lH0V0/6NC2ttKMbMd6kGfbVXxGZUlcyLJjGtYEfPLl2XcXGczajMJZ6bFNyAQl2e DynQ== Received: by 10.68.132.165 with SMTP id ov5mr53449192pbb.19.1343223818394; Wed, 25 Jul 2012 06:43:38 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id og4sm14410289pbb.48.2012.07.25.06.43.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jul 2012 06:43:37 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH 05/18] insert: move file from Maildir tmp to new Date: Wed, 25 Jul 2012 23:42:34 +1000 Message-Id: <1343223767-9812-5-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com> References: <1343223767-9812-1-git-send-email-novalazy@gmail.com> 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: Wed, 25 Jul 2012 13:43:40 -0000 Atomically move the new message file from the Maildir 'tmp' directory to 'new'. --- notmuch-insert.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 340f7e4..bab1fed 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -75,6 +75,20 @@ maildir_open_tmp (void *ctx, const char *dir, char **tmppath, char **newpath) } static notmuch_bool_t +maildir_move_to_new (const char *tmppath, const char *newpath) +{ + /* We follow the Dovecot recommendation to simply use rename() + * instead of link() and unlink(). + */ + if (rename (tmppath, newpath) == 0) { + return TRUE; + } + + fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno)); + return FALSE; +} + +static notmuch_bool_t copy_fd_data (int fdin, int fdout) { char buf[4096]; @@ -132,6 +146,10 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, close (fdout); + if (ret) { + ret = maildir_move_to_new (tmppath, newpath); + } + if (!ret) { unlink (tmppath); } -- 1.7.4.4