From: Taylor Blau <me@ttaylorr.com>
To: Glen Choo <chooglen@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Glen Choo via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org
Subject: Re: [PATCH] clone: error specifically with --local and symlinked objects
Date: Thu, 6 Apr 2023 17:35:29 -0400 [thread overview]
Message-ID: <ZC87IcLcBnxBRCdr@nand.local> (raw)
In-Reply-To: <kl6ly1n65l7t.fsf@chooglen-macbookpro.roam.corp.google.com>
On Wed, Apr 05, 2023 at 09:48:22AM -0700, Glen Choo wrote:
> Since this is an error code path, I think the extra lstat() is probably
> worth it since it lets us be really specific about the error. Maybe:
FWIW, I don't totally think it's necessary for us to report back to the
user that they're trying to clone a repository with `--local` whose
`$GIT_DIR/objects` either is or contains a symbolic link. Especially so
since you're already updating the documentation here.
But I think it's a compelling argument in the name of improving the user
experience, so I think that this is a reasonable direction. And I agree,
that while the extra lstat() is unfortunate, I don't think there is a
convenient way to do it otherwise.
We *could* teach the dir-iterator API to return a specialized error code either
through a pointer, like:
struct dir_iterator *dir_iterator_begin(const char *path,
unsigned int flags, int *error)
and set error to something like -DIR_ITERATOR_IS_SYMLINK when error is
non-NULL.
Or we could do something like this:
int dir_iterator_begin(struct dir_iterator **it,
const char *path, unsigned int flags)
and have the `dir_iterator_begin()` function return its specialized
error and initialize the dir iterator through a pointer. Between these
two, I prefer the latter, but I think it's up to individual taste.
> if (!iter) {
> struct stat st;
>
> if (errno == ENOTDIR && lstat(src->buf, &st) == 0 && S_ISLNK(st.st_mode))
Couple of nit-picks here. Instead of writing "lstat(src->buf, &st ==
0)", we should write "!lstat(src->buf, &st)" to match
Documentation/CodingGuidelines.
But note that that call to lstat() will clobber your errno value, so
you'd want to save it off beforehand. If you end up going this route,
I'd probably do something like:
if (!iter) {
int saved_errno = errno;
if (errno == ENOTDIR) {
struct stat st;
if (!lstat(src->buf, &st) && S_ISLNK(st.st_mode))
die(_("'%s' is a symlink, refusing to clone with `--local`"),
src->buf);
}
errno = saved_errno;
die_errno(_("failed to start iterator over '%s'"), src->buf);
}
Thanks,
Taylor
next prev parent reply other threads:[~2023-04-06 21:35 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
2023-04-05 16:48 ` Glen Choo
2023-04-05 19:20 ` Junio C Hamano
2023-04-06 21:35 ` Taylor Blau [this message]
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=ZC87IcLcBnxBRCdr@nand.local \
--to=me@ttaylorr.com \
--cc=chooglen@google.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.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).