[PATCH v3 3/4] new: Merge error checks from add_files and add_files_recursive
authorAustin Clements <amdragon@MIT.EDU>
Thu, 24 May 2012 19:32:01 +0000 (15:32 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:20 +0000 (09:47 -0800)
96/2b6d345d065e046d8020704819cb03f1bd5be3 [new file with mode: 0644]

diff --git a/96/2b6d345d065e046d8020704819cb03f1bd5be3 b/96/2b6d345d065e046d8020704819cb03f1bd5be3
new file mode 100644 (file)
index 0000000..d65a29c
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <amdragon@mit.edu>\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 7B587431FCF\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 12:32:10 -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 C+OCvemrQEsZ for <notmuch@notmuchmail.org>;\r
+       Thu, 24 May 2012 12:32:09 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+       [18.7.68.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 29750431E62\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 12:32:09 -0700 (PDT)\r
+X-AuditID: 12074422-b7fd66d0000008f9-07-4fbe8cb78529\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id ED.9B.02297.7BC8EBF4; Thu, 24 May 2012 15:32:07 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q4OJW7I7025151; \r
+       Thu, 24 May 2012 15:32:07 -0400\r
+Received: from drake.mit.edu (26-4-163.dynamic.csail.mit.edu [18.26.4.163])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4OJW5cB014461\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 24 May 2012 15:32:06 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SXdlT-0003Rc-U3; Thu, 24 May 2012 15:32:03 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 3/4] new: Merge error checks from add_files and\r
+       add_files_recursive\r
+Date: Thu, 24 May 2012 15:32:01 -0400\r
+Message-Id: <1337887922-13163-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1337887922-13163-1-git-send-email-amdragon@mit.edu>\r
+References: <1336429240-1114-1-git-send-email-amdragon@mit.edu>\r
+       <1337887922-13163-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrbu9Z5+/QetLC4vrN2cyOzB6PFt1\r
+       izmAMYrLJiU1J7MstUjfLoEr49EU64LD/BVzL7WwNDBO5Oli5OSQEDCRWPXiNSuELSZx4d56\r
+       ti5GLg4hgX2MEsd+z2CGcDYwSryccQXKOc4ksbP1GAuEM4tRovtnFzNIP5uAhsS2/csZQWwR\r
+       AWmJnXdnA83l4GAWUJP406UCEhYWCJPYPn0rC4jNIqAq0bH8MZjNK+Ag8ebZREaIM+Qlnt7v\r
+       YwOxOQUcJS48mcwEYgsJlEkcf7yLaQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6pnq5\r
+       mSV6qSmlmxhBQcPuorSD8edBpUOMAhyMSjy8LNH7/IVYE8uKK3MPMUpyMCmJ8vJ1A4X4kvJT\r
+       KjMSizPii0pzUosPMUpwMCuJ8ApGAuV4UxIrq1KL8mFS0hwsSuK8azR3+wsJpCeWpGanphak\r
+       FsFkZTg4lCR4WYDRISRYlJqeWpGWmVOCkGbi4AQZzgM0fB/IYt7igsTc4sx0iPwpRkUpcd6L\r
+       IAkBkERGaR5cLyyqXzGKA70izPsXpIoHmBDgul8BDWYCGrzl8V6QwSWJCCmpBsaShuiJaxrb\r
+       nvvvrVndqLRNzlzOdFnIpvTpzF3JVz/0bX1230GstPXnVCYjRmt3xkb/rNuZP77dyO7Wrp15\r
+       XvO7wppzk37yF/6p+qho9fnwe+71wuceTF1y5NEmdTXhFTWKLwO+r+i5qhljzx+XEliTf8H/\r
+       5PJkUfbDzFzMs1XDonifXJJ1D1JiKc5INNRiLipOBAAyaYvZxQIAAA==\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: Thu, 24 May 2012 19:32:10 -0000\r
+\r
+Before XXX, add_files_recursive could have been called on a symlink to\r
+a non-directory.  Hence, calling it on a non-directory was not an\r
+error, so a separate function, add_files, existed to fail loudly in\r
+situations where the path had to be a directory.\r
+\r
+With the new stat-ing logic, add_files_recursive is always called on\r
+directories, so the separation of this logic is no longer necessary.\r
+Hence, this patch moves the strict error checking previously done by\r
+add_files into add_files_recursive.\r
+---\r
+ notmuch-new.c |   27 +++++----------------------\r
+ 1 file changed, 5 insertions(+), 22 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index c64f1a7..2b05605 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -308,11 +308,10 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+     }\r
+     stat_time = time (NULL);\r
\r
+-    /* This is not an error since we may have recursed based on a\r
+-     * symlink to a regular file, not a directory, and we don't know\r
+-     * that until this stat. */\r
+-    if (! S_ISDIR (st.st_mode))\r
+-      return NOTMUCH_STATUS_SUCCESS;\r
++    if (! S_ISDIR (st.st_mode)) {\r
++      fprintf (stderr, "Error: %s is not a directory.\n", path);\r
++      return NOTMUCH_STATUS_FILE_ERROR;\r
++    }\r
\r
+     fs_mtime = st.st_mtime;\r
\r
+@@ -655,23 +654,7 @@ add_files (notmuch_database_t *notmuch,\r
+          const char *path,\r
+          add_files_state_t *state)\r
+ {\r
+-    notmuch_status_t status;\r
+-    struct stat st;\r
+-\r
+-    if (stat (path, &st)) {\r
+-      fprintf (stderr, "Error reading directory %s: %s\n",\r
+-               path, strerror (errno));\r
+-      return NOTMUCH_STATUS_FILE_ERROR;\r
+-    }\r
+-\r
+-    if (! S_ISDIR (st.st_mode)) {\r
+-      fprintf (stderr, "Error: %s is not a directory.\n", path);\r
+-      return NOTMUCH_STATUS_FILE_ERROR;\r
+-    }\r
+-\r
+-    status = add_files_recursive (notmuch, path, state);\r
+-\r
+-    return status;\r
++    return add_files_recursive (notmuch, path, state);\r
+ }\r
\r
+ /* XXX: This should be merged with the add_files function since it\r
+-- \r
+1.7.10\r
+\r