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