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