From: Junio C Hamano <gitster@pobox.com>
To: "Glen Choo via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Taylor Blau <me@ttaylorr.com>,
Glen Choo <chooglen@google.com>
Subject: Re: [PATCH] clone: error specifically with --local and symlinked objects
Date: Tue, 04 Apr 2023 17:13:41 -0700 [thread overview]
Message-ID: <xmqq7curxk22.fsf@gitster.g> (raw)
In-Reply-To: <pull.1488.git.git.1680652122547.gitgitgadget@gmail.com> (Glen Choo via GitGitGadget's message of "Tue, 04 Apr 2023 23:48:42 +0000")
"Glen Choo via GitGitGadget" <gitgitgadget@gmail.com> writes:
> iter = dir_iterator_begin(src->buf, DIR_ITERATOR_PEDANTIC);
>
> - if (!iter)
> + if (!iter) {
> + struct stat st;
> + if (lstat(src->buf, &st) >= 0 && S_ISLNK(st.st_mode))
> + die(_("'%s' is a symlink, refusing to clone with --local"),
> + src->buf);
If you want to do lstat(2) yourself, the canonical way to check its
success is to see the returned value is 0, not "not negative", but
let's first see how dir_iterator_begin() can fail. I suspect it may
not necessary to do another lstat(2). The function returns NULL:
* if lstat() fails; errno is left from the failed lstat() in this case.
* if lstat() succeeds, but the path is *not* a directory; errno is
explicitly set to ENOTDIR. Unfortunately, if lstat(2) failed
with ENOTDIR (e.g. dir_iterator_begin() gets called with a path
whose leading component is not a directory), the caller will also
see ENOTDIR, but the distinction may not matter in practice. I
haven't thought things through.
Assuming that the distinction does not matter, then,
if (!iter) {
if (errno == ENOTDIR)
die(_("'%s' is not a directory, refusing to clone with --local"),
src->buf);
else
die_errno(_("failed to stat '%s'"), src->buf);
}
may be sufficient. But because this is an error codepath, it is not
worth optimizing what happens there, and an extra lstat(2) is not
too bad, if the code gains extra clarity.
next prev parent reply other threads:[~2023-04-05 0:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 23:48 [PATCH] clone: error specifically with --local and symlinked objects Glen Choo via GitGitGadget
2023-04-05 0:13 ` Junio C Hamano [this message]
2023-04-05 16:48 ` Glen Choo
2023-04-05 19:20 ` Junio C Hamano
2023-04-06 21:35 ` Taylor Blau
2023-04-06 21:55 ` Glen Choo
2023-04-06 21:27 ` Taylor Blau
2023-04-10 22:18 ` [PATCH v2] " Glen Choo via GitGitGadget
2023-04-10 22:27 ` Junio C Hamano
2023-04-10 23:16 ` Taylor Blau
2023-04-11 1:58 ` Taylor Blau
2023-04-11 17:08 ` [PATCH v3] " Glen Choo via GitGitGadget
2023-04-11 17:13 ` Junio C Hamano
2023-04-11 18:38 ` Glen Choo
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=xmqq7curxk22.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chooglen@google.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=me@ttaylorr.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).