[PATCH 05/18] insert: move file from Maildir tmp to new
authorPeter Wang <novalazy@gmail.com>
Wed, 25 Jul 2012 13:42:34 +0000 (23:42 +1000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:35 +0000 (09:48 -0800)
dd/c55552bfefe39ea3891cb7c611d42e8f076778 [new file with mode: 0644]

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