[PATCH v4 3/4] new: Merge error checks from add_files and add_files_recursive
authorAustin Clements <amdragon@MIT.EDU>
Thu, 24 May 2012 22:01:12 +0000 (18:01 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:21 +0000 (09:47 -0800)
50/9795bcd15af963e6a3c718698ab154e6e1af77 [new file with mode: 0644]

diff --git a/50/9795bcd15af963e6a3c718698ab154e6e1af77 b/50/9795bcd15af963e6a3c718698ab154e6e1af77
new file mode 100644 (file)
index 0000000..7c72dd7
--- /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 4FA6C429E36\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 15:01:24 -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 ZSORz-6Iq3Uv for <notmuch@notmuchmail.org>;\r
+       Thu, 24 May 2012 15:01:23 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+       [18.9.25.12])\r
+       by olra.theworths.org (Postfix) with ESMTP id 50A9C431FCF\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 15:01:23 -0700 (PDT)\r
+X-AuditID: 1209190c-b7fad6d000000920-9c-4fbeafb2b975\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 34.7B.02336.2BFAEBF4; Thu, 24 May 2012 18:01:23 -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 q4OM1Mf4018143; \r
+       Thu, 24 May 2012 18:01:22 -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 q4OM1LnN009160\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 24 May 2012 18:01:22 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SXg5w-00064Z-2R; Thu, 24 May 2012 18:01:20 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/4] new: Merge error checks from add_files and\r
+       add_files_recursive\r
+Date: Thu, 24 May 2012 18:01:12 -0400\r
+Message-Id: <1337896873-23253-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1337896873-23253-1-git-send-email-amdragon@mit.edu>\r
+References: <1337887922-13163-1-git-send-email-amdragon@mit.edu>\r
+       <1337896873-23253-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrbt5/T5/gz3HmCyu35zJ7MDo8WzV\r
+       LeYAxigum5TUnMyy1CJ9uwSujMNHdjEWHOavmNO0k72BcRJPFyMnh4SAicTWaxMYIWwxiQv3\r
+       1rN1MXJxCAnsY5TY/mUOE4SzgVHi5ckzUM5xJolzF5qgymYxSjz+No0NpJ9NQENi2/7lYLNE\r
+       BKQldt6dzdrFyMHBLKAm8adLBSQsLBAmsenLPGYQm0VAVeLErx1MICW8Ag4Sj/7yQlwhL/H0\r
+       fh/YRE4BR4nHZ3+BTRQSKJe4fGMuywRG/gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0DfVy\r
+       M0v0UlNKNzGCg0aSZwfjm4NKhxgFOBiVeHiZo/f5C7EmlhVX5h5ilORgUhLl/bEaKMSXlJ9S\r
+       mZFYnBFfVJqTWnyIUYKDWUmEVzASKMebklhZlVqUD5OS5mBREuddqbnbX0ggPbEkNTs1tSC1\r
+       CCYrw8GhJMF7cB1Qo2BRanpqRVpmTglCmomDE2Q4D9DwzyA1vMUFibnFmekQ+VOMilLivE9A\r
+       EgIgiYzSPLheWFS/YhQHekWY9ztIFQ8wIcB1vwIazAQ0eMvjvSCDSxIRUlINjJ5lBlsTbZ/d\r
+       yY7hmL+R5ygj049krsSLz1NNJa97KsZxPjbvufv44uuFArrNj6SU1xg0O25csKNPfNv2JUcv\r
+       Cu7tOdtSu0Vsx6foC4lH+tZwWLPwX6rRZI29vnwL+0ZO6055ra4/MZev7n3o6C980mi59P+d\r
+       Bz6l7D172y3nQMOO9A/XdZZpNSuxFGckGmoxFxUnAgBrK8sVxQIAAA==\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 22:01:24 -0000\r
+\r
+Previously, 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