git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] clone: error specifically with --local and symlinked objects

From
Glen Choo <chooglen@google.com>
Date
Apr 6, 2023, 21:55 UTC
Message-ID
<kl6lmt3k3ccc.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<ZC87IcLcBnxBRCdr@nand.local>
Thanks for the feedback!
(and phew, I was a few minutes away from submitting v2 :P)
Taylor Blau <me@ttaylorr.com> writes:
Show 17 quoted lines
> 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.

Yeah, I've thought about doing the latter. That's also what I'd prefer. Since you've brought it up, I'll give that a try.

Show 8 quoted lines
>> 	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.
Ah, thanks.
Show 17 quoted lines
> 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);
>     }

Ah thanks, yes. I think it isn't different in practice, since we're lstat()-ing the same path, but we should always use the "real" errno to be safe.

This is another good reason to return an error code instead of overloading errno.

Previous: Taylor BlauNext: Taylor Blau
Message 6 of 14 in “clone: error specifically with --local and symlinked objects”
  1. clone: error specifically with --local and symlinked objectsGlen Choo via GitGitGadget, Apr 4, 2023
  2. Junio C HamanoApr 5, 2023
  3. Glen ChooApr 5, 2023
  4. Junio C HamanoApr 5, 2023
  5. Taylor BlauApr 6, 2023
  6. Glen ChooApr 6, 2023
  7. Taylor BlauApr 6, 2023
  8. clone: error specifically with --local and symlinked objectsGlen Choo via GitGitGadget, Apr 10, 2023
  9. Junio C HamanoApr 10, 2023
  10. Taylor BlauApr 10, 2023
  11. Taylor BlauApr 11, 2023
  12. clone: error specifically with --local and symlinked objectsGlen Choo via GitGitGadget, Apr 11, 2023
  13. Junio C HamanoApr 11, 2023
  14. Glen ChooApr 11, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.