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

[PATCH] Use sha1_file.c's mkdir-like routine in apply.c.

From
Jason Riedy <ejr@eecs.berkeley.edu>
Date
Feb 4, 2006, 06:50 UTC
Message-ID
<17347.1139035857@lotus.CS.Berkeley.EDU>

As far as I can see, create_subdirectories() in apply.c just duplicates the functionality of safe_create_leading_directories() from sha1_file.c. The former has a warm, fuzzy const parameter, but that's not important.

The potential problem with EEXIST and creating directories should never occur here, but will be removed by future safe_create_leading_directories() changes. Other uses of EEXIST in apply.c should be fine barring intentionally malicious behavior.

Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
---
 apply.c |   25 ++++---------------------
 1 files changed, 4 insertions(+), 21 deletions(-)
9f6bc2c90544688c2aad0ad0da4b2674f5aa6fab
diff --git a/apply.c b/apply.c
index 79e23a7..2ad47fb 100644
--- a/apply.c
+++ b/apply.c
@@ -1564,24 +1564,6 @@ static void add_index_file(const char *p
 		die("unable to add cache entry for %s", path);
 }
 
-static void create_subdirectories(const char *path)
-{
-	int len = strlen(path);
-	char *buf = xmalloc(len + 1);
-	const char *slash = path;
-
-	while ((slash = strchr(slash+1, '/')) != NULL) {
-		len = slash - path;
-		memcpy(buf, path, len);
-		buf[len] = 0;
-		if (mkdir(buf, 0777) < 0) {
-			if (errno != EEXIST)
-				break;
-		}
-	}
-	free(buf);
-}
-
 static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
 {
 	int fd;
@@ -1610,13 +1592,14 @@ static int try_create_file(const char *p
  * which is true 99% of the time anyway. If they don't,
  * we create them and try again.
  */
-static void create_one_file(const char *path, unsigned mode, const char *buf, unsigned long size)
+static void create_one_file(char *path, unsigned mode, const char *buf, unsigned long size)
 {
 	if (!try_create_file(path, mode, buf, size))
 		return;
 
 	if (errno == ENOENT) {
-		create_subdirectories(path);
+		if (safe_create_leading_directories(path))
+			return;
 		if (!try_create_file(path, mode, buf, size))
 			return;
 	}
@@ -1643,7 +1626,7 @@ static void create_one_file(const char *
 
 static void create_file(struct patch *patch)
 {
-	const char *path = patch->new_name;
+	char *path = patch->new_name;
 	unsigned mode = patch->new_mode;
 	unsigned long size = patch->resultsize;
 	char *buf = patch->result;
-- 
1.1.5
Message 1 of 1 in “Use sha1_file.c's mkdir-like routine in apply.c.”
  1. Use sha1_file.c's mkdir-like routine in apply.c.Jason Riedy, Feb 4, 2006

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.