Skip to content

Commit

Permalink
safe_create_leading_directories(): split on first of multiple slashes
Browse files Browse the repository at this point in the history
If the input path has multiple slashes between path components (e.g.,
"foo//bar"), then the old code was breaking the path at the last
slash, not the first one.  So in the above example, the second slash
was overwritten with NUL, resulting in the parent directory being
sought as "foo/".

When stat() is called on "foo/", it fails with ENOTDIR if "foo" exists
but is not a directory.  This caused the wrong path to be taken in the
subsequent logic.

So instead, split path components at the first intercomponent slash
rather than the last one.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jan 6, 2014
1 parent 26c8ae2 commit bf10cf7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ int safe_create_leading_directories(char *path)

if (!slash)
break;
while (*(slash + 1) == '/')
slash++;

next_component = slash + 1;
while (*next_component == '/')
next_component++;
if (!*next_component)
break;

Expand Down

0 comments on commit bf10cf7

Please sign in to comment.