Re: [PATCH] ignore trailing slash when creating leading directories

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] ignore trailing slash when creating leading directories

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:17

Junio C Hamano [off-list ref] writes:
I am not saying the current semantics of c-l-d is optimal.  I am just
worried about breaking people's private patches that may depend on the
current behaviour.  It would be nice if we can clean it up without
breaking people, and after doing so, if somebody really want to have
"create all directories, the last one is also a directory", they can
invent a cleaner function that takes that insn as a separate paremeter,
not as an obscure "trailing slash means create all", which may be cute but
not clean nor clear at all, which is what c-l-d does.
And just so that you do not misunderstand that I am opposed to the change
to c-l-d, here is a replacement to your original patch.  I didn't fix the
caller, as I didn't want to do an overlapping fix with you.

-- >8 --
safe_create_leadign_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
(because it forgets to verify the user input, perhaps) 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 <redacted>
---
 sha1_file.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git i/sha1_file.c w/sha1_file.c
index 9ee1ed1..bc6176e 100644
--- i/sha1_file.c
+++ w/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)) {

Re: [PATCH] ignore trailing slash when creating leading directories

From: Clemens Buchacher <hidden>
Date: 2016-06-15 22:45:17

On Tue, Sep 02, 2008 at 02:10:15PM -0700, Junio C Hamano wrote:
And just so that you do not misunderstand that I am opposed to the change
to c-l-d, here is a replacement to your original patch.  I didn't fix the
caller, as I didn't want to do an overlapping fix with you.
You beat me to it - again. :-) But I like yours much better.

Clemens
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help