Re: [PATCH v3 3/4] new: Merge error checks from add_files and add_files_recursive
authorJani Nikula <jani@nikula.org>
Thu, 24 May 2012 20:57:45 +0000 (23:57 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:20 +0000 (09:47 -0800)
3e/8666b25942e598efea992513524aa45b2efc72 [new file with mode: 0644]

diff --git a/3e/8666b25942e598efea992513524aa45b2efc72 b/3e/8666b25942e598efea992513524aa45b2efc72
new file mode 100644 (file)
index 0000000..2abcf3c
--- /dev/null
@@ -0,0 +1,147 @@
+Return-Path: <jani@nikula.org>\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 A5311431E62\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 13:57:48 -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=unavailable\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 QQeorfyckHPO for <notmuch@notmuchmail.org>;\r
+       Thu, 24 May 2012 13:57:48 -0700 (PDT)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 3F4CA431FBD\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 13:57:48 -0700 (PDT)\r
+Received: by mail-lb0-f181.google.com with SMTP id gk8so179779lbb.26\r
+       for <notmuch@notmuchmail.org>; Thu, 24 May 2012 13:57:47 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type:x-gm-message-state;\r
+       bh=coa1rnBnz553nybF0VZC4Z++LLTJzrA4mctnfpAOhvY=;\r
+       b=DkqxR2V6z8guI9XUA8b4ll46GEk3KsC+b6mBExhhM+8u1whJhY24rnNQjcwXyBkP35\r
+       s36eMvoWnWqfN3vI+cr80CEYHM6wKsm7YdBqVpDzTThN4BJvZUKuPXxmtop+hDFKXUvu\r
+       T/fT7dfBr+8Qzd1DQftJJHT94UCRuQMrX/c22Im6C24cPeVfNFDnO4M+0hx+OxjAqCvX\r
+       LADyBtwiaFwSYxVfyICGm8b4fQd8IqZ2u94UuFDGmkH5pGFf4hd2aJEa2Rlbvi6T8kOE\r
+       TN8Rna8HlsmpxzlbV5JfGzSEwfLE3EP3P/XxPF4jddFQFQnxOD3QsuPV6dB5VaPeMCLe\r
+       nqOA==\r
+Received: by 10.112.48.2 with SMTP id h2mr383590lbn.61.1337893067767;\r
+       Thu, 24 May 2012 13:57:47 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.\r
+       [80.220.80.68])\r
+       by mx.google.com with ESMTPS id h9sm1878668lbi.9.2012.05.24.13.57.46\r
+       (version=SSLv3 cipher=OTHER); Thu, 24 May 2012 13:57:47 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 3/4] new: Merge error checks from add_files and\r
+       add_files_recursive\r
+In-Reply-To: <1337887922-13163-4-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
+       <1337887922-13163-4-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.13+13~gc259b9a (http://notmuchmail.org) Emacs/23.3.1\r
+       (i686-pc-linux-gnu)\r
+Date: Thu, 24 May 2012 23:57:45 +0300\r
+Message-ID: <87vcjl5mba.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQkuVJALtcdTBqvFIf7EB0ujgh65AXds2GVydZDES61EJ29/+1XjstPMq+pWgsdy4Nj2serx\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 20:57:48 -0000\r
+\r
+On Thu, 24 May 2012, Austin Clements <amdragon@MIT.EDU> wrote:\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
+"Before XXX"?\r
+\r
+Otherwise, this 3/4 and following 4/4 patch LGTM. I didn't bother\r
+looking at 1/4 and 2/4 again, as you say there were no changes.\r
+\r
+\r
+BR,\r
+Jani.\r
+\r
+\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r