From: Michael Haggerty Date: Sat, 18 Jan 2014 23:40:44 +0000 (+0100) Subject: safe_create_leading_directories(): on Windows, \ can separate path components X-Git-Tag: v1.9-rc1~9^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0f5274033ecb0262dc77e4ed48fdb1ab07181bd8;p=thirdparty%2Fgit.git safe_create_leading_directories(): on Windows, \ can separate path components When cloning to a directory "C:\foo\bar" from Windows' cmd.exe where "foo" does not exist yet, Git would throw an error like fatal: could not create work tree dir 'c:\foo\bar'.: No such file or directory Fix this by not hard-coding a platform specific directory separator into safe_create_leading_directories(). This patch, including its entire commit message, is derived from a patch by Sebastian Schuberth. Signed-off-by: Johannes Schindelin Signed-off-by: Sebastian Schuberth Signed-off-by: Junio C Hamano Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- diff --git a/sha1_file.c b/sha1_file.c index ed814e546f..bba70e7970 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -112,17 +112,21 @@ enum scld_error safe_create_leading_directories(char *path) while (ret == SCLD_OK && next_component) { struct stat st; - char *slash = strchr(next_component, '/'); + char *slash = next_component, slash_character; - if (!slash) + while (*slash && !is_dir_sep(*slash)) + slash++; + + if (!*slash) break; next_component = slash + 1; - while (*next_component == '/') + while (is_dir_sep(*next_component)) next_component++; if (!*next_component) break; + slash_character = *slash; *slash = '\0'; if (!stat(path, &st)) { /* path exists */ @@ -148,7 +152,7 @@ enum scld_error safe_create_leading_directories(char *path) } else if (adjust_shared_perm(path)) { ret = SCLD_PERMS; } - *slash = '/'; + *slash = slash_character; } return ret; }