git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] ignore trailing slashes when creating leading directories

From
Clemens Buchacher <drizzd@aon.at>
Date
Sep 2, 2008, 20:07 UTC
Message-ID
<20080902200759.GA13451@localhost>
In-Reply-To
<20080902191322.GA11172@localhost>

Currently, create_leading_directories() will interpret all parts of paths like 'a/b/c/' as "leading directories". A subsequent call to mkdir for the tail of the path will fail, because the "File already exists."

This makes sure trailing slashes are ignored.
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
Applies to next. Passes regression tests.
 sha1_file.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 9ee1ed1..dcb3d22 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -93,12 +93,19 @@ static inline int offset_1st_component(const char *path)
 int safe_create_leading_directories(char *path)
 {
 	char *pos = path + offset_1st_component(path);
+	char *next;
 	struct stat st;
 
 	while (pos) {
 		pos = strchr(pos, '/');
 		if (!pos)
 			break;
+		next = pos + 1;
+		while (*next == '/')
+			next++;
+		if (!*next)
+			break;
+
 		*pos = 0;
 		if (!stat(path, &st)) {
 			/* path exists */
-- 
1.6.0.1.275.gc88b6
Previous: Clemens BuchacherNext: Junio C Hamano
Message 4 of 9 in “ignore trailing slash when creating leading directories”
  1. ignore trailing slash when creating leading directoriesClemens Buchacher, Sep 2, 2008
  2. Junio C HamanoSep 2, 2008
  3. Clemens BuchacherSep 2, 2008
  4. ignore trailing slashes when creating leading directoriesClemens Buchacher, Sep 2, 2008
  5. Junio C HamanoSep 2, 2008
  6. Junio C HamanoSep 2, 2008
  7. Clemens BuchacherSep 3, 2008
  8. clone: fix creation of explicitly named target directoryClemens Buchacher, Sep 3, 2008
  9. Junio C HamanoSep 3, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.