Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-09-03 01:10:15 +0400
committerJunio C Hamano <gitster@pobox.com>2008-09-04 09:35:32 +0400
commit5f0bdf50c2eb640b4321acb9b34b3cb401f5ddfb (patch)
tree43d9939712c4793f4f68edd8f851917c7d5622e7 /sha1_file.c
parentde5d560c99c96e2955fb4d1d8a8fa6b469926292 (diff)
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: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 477d3fb4b0..f85c8cec35 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)) {