提交 5f0bdf50 编写于 作者: J Junio C Hamano

safe_create_leading_directories(): make it about "leading" directories

We used to allow callers to pass "foo/bar/" to make sure both "foo" and
"foo/bar" exist and have good permissions, but this interface is too error
prone.  If a caller mistakenly passes a path with trailing slashes
(perhaps it forgot to verify the user input) even when it wants to later
mkdir "bar" itself, it will find that it cannot mkdir "bar".  If such a
caller does not bother to check the error for EEXIST, it may even
errorneously die().

Because we have no existing callers to use that obscure feature, this
patch removes it to avoid confusion.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 de5d560c
......@@ -99,7 +99,11 @@ int safe_create_leading_directories(char *path)
pos = strchr(pos, '/');
if (!pos)
break;
*pos = 0;
while (*++pos == '/')
;
if (!*pos)
break;
*--pos = '\0';
if (!stat(path, &st)) {
/* path exists */
if (!S_ISDIR(st.st_mode)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册