From: Junio C Hamano <gitster@pobox.com>
To: "qusielle via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/1] add: respect `--ignore-errors` when `lstat()` reports errors
Date: Mon, 28 Oct 2019 11:03:28 +0900 [thread overview]
Message-ID: <xmqq36fdbp8v.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <fd022f88f54f6cf0feb61965b2dc47bca64c0937.1572127149.git.gitgitgadget@gmail.com> (qusielle via GitGitGadget's message of "Sat, 26 Oct 2019 21:59:09 +0000")
"qusielle via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: qusielle <31454380+qusielle@users.noreply.github.com>
>
> "git add --ignore-errors" command fails immediately when lstat returns
> an error, despite the ignore errors' flag is enabled.
> ...
> diff --git a/read-cache.c b/read-cache.c
> index 133f790fa4..67237ecd29 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -801,7 +801,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
> int add_file_to_index(struct index_state *istate, const char *path, int flags)
> {
> struct stat st;
> - if (lstat(path, &st))
> + if (lstat(path, &st) && !(flags & ADD_CACHE_IGNORE_ERRORS))
> die_errno(_("unable to stat '%s'"), path);
> return add_to_index(istate, path, &st, flags);
> }
The only callers of this function that matter calls it and then
responds to an error return like so:
(in builtin/add.c::update_callback())
if (add_file_to_index(&the_index, path, data->flags)) {
if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
die(_("updating files failed"));
(in builtin/add.c::add_files(), where ignore_add_errors was used to
set the ADD_CACHE_IGNORE_ERRORS to flags in its caller)
if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {
if (!ignore_add_errors)
die(_("adding files failed"));
So you correctly identified what is the right place to fix. We
should not "die_errno()"; we should give the control back to the
caller instead.
But after a failed stat, the code with your patch still calls
add_to_index() using the now undefined stat data, which would
contaminate the in-core index with wrong data.
I think we should instead return without touching the index for the
path we had trouble lstat()ing.
IOW
if (lstat(path, &st)) {
if (flags & ADD_CACHE_IGNORE_ERRORS)
return -1;
else
die_errno(_("unable to ..."));
}
return add_to_index(...);
next prev parent reply other threads:[~2019-10-28 2:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-26 21:59 [PATCH 0/1] add: respect --ignore-errors when lstat() reports errors Qusielle via GitGitGadget
2019-10-26 21:59 ` [PATCH 1/1] add: respect `--ignore-errors` when `lstat()` " qusielle via GitGitGadget
2019-10-28 2:03 ` Junio C Hamano [this message]
2019-11-03 20:17 ` qusielle
2019-11-03 20:26 ` [PATCH v2 0/1] add: respect --ignore-errors when lstat() " Qusielle via GitGitGadget
2019-11-03 20:26 ` [PATCH v2 1/1] add: respect `--ignore-errors` when `lstat()` " qusielle via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq36fdbp8v.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).