Michael Haggerty <mhag...@alum.mit.edu> writes:

> The exit path for SCLD_EXISTS wasn't setting errno, as expected by at
> least one caller. Fix the problem and document that the function sets
> errno correctly to help avoid similar regressions in the future.

> diff --git a/sha1_file.c b/sha1_file.c
> index 568120e..a1ac646 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -135,8 +135,10 @@ enum scld_error safe_create_leading_directories(char 
> *path)
>               *slash = '\0';
>               if (!stat(path, &st)) {
>                       /* path exists */
> -                     if (!S_ISDIR(st.st_mode))
> +                     if (!S_ISDIR(st.st_mode)) {
> +                             errno = EEXIST;
>                               ret = SCLD_EXISTS;

Hmm, when does this trigger?  There is a non-directory A/B, you are
preparing leading directories to create A/B/C/D, and you find A/B
exists but is not a directory so you cannot create A/B/C underneath
it?

That sounds more like ENOTDIR to me.

Does the caller expect EEXIST, or both?

> +                     }
>               } else if (mkdir(path, 0777)) {
>                       if (errno == EEXIST &&
>                           !stat(path, &st) && S_ISDIR(st.st_mode))
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to