{"thread":{"id":"3236","subject":"[PATCH] Use sha1_file.c's mkdir-like routine in apply.c.","startedAt":"2006-02-04T06:50:57Z","lastAt":"2006-02-04T06:50:57Z","messageCount":1,"participants":["Jason Riedy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"15556","messageId":"17347.1139035857@lotus.CS.Berkeley.EDU","threadId":"3236","inReplyTo":null,"subject":"[PATCH] Use sha1_file.c's mkdir-like routine in apply.c.","fromName":"Jason Riedy","fromEmail":"ejr@eecs.berkeley.edu","sentAt":"2006-02-04T06:50:57Z","receivedAt":"2006-02-04T06:50:57Z","isPatch":true,"sender":{"key":"ejr@eecs.berkeley.edu","avatar":"https://gravatar.com/avatar/547fa56f887cab01599edab4e9f813c949c1269e02714f20e0496c56185d9837?d=mp&s=160"},"body":"As far as I can see, create_subdirectories() in apply.c just\nduplicates the functionality of safe_create_leading_directories() from\nsha1_file.c.  The former has a warm, fuzzy const parameter, but that's\nnot important.\n\nThe potential problem with EEXIST and creating directories should\nnever occur here, but will be removed by future\nsafe_create_leading_directories() changes.  Other uses of EEXIST in\napply.c should be fine barring intentionally malicious behavior.\n\nSigned-off-by: Jason Riedy <ejr@cs.berkeley.edu>\n\n---\n\n apply.c |   25 ++++---------------------\n 1 files changed, 4 insertions(+), 21 deletions(-)\n\n9f6bc2c90544688c2aad0ad0da4b2674f5aa6fab\ndiff --git a/apply.c b/apply.c\nindex 79e23a7..2ad47fb 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -1564,24 +1564,6 @@ static void add_index_file(const char *p\n \t\tdie(\"unable to add cache entry for %s\", path);\n }\n \n-static void create_subdirectories(const char *path)\n-{\n-\tint len = strlen(path);\n-\tchar *buf = xmalloc(len + 1);\n-\tconst char *slash = path;\n-\n-\twhile ((slash = strchr(slash+1, '/')) != NULL) {\n-\t\tlen = slash - path;\n-\t\tmemcpy(buf, path, len);\n-\t\tbuf[len] = 0;\n-\t\tif (mkdir(buf, 0777) < 0) {\n-\t\t\tif (errno != EEXIST)\n-\t\t\t\tbreak;\n-\t\t}\n-\t}\n-\tfree(buf);\n-}\n-\n static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)\n {\n \tint fd;\n@@ -1610,13 +1592,14 @@ static int try_create_file(const char *p\n  * which is true 99% of the time anyway. If they don't,\n  * we create them and try again.\n  */\n-static void create_one_file(const char *path, unsigned mode, const char *buf, unsigned long size)\n+static void create_one_file(char *path, unsigned mode, const char *buf, unsigned long size)\n {\n \tif (!try_create_file(path, mode, buf, size))\n \t\treturn;\n \n \tif (errno == ENOENT) {\n-\t\tcreate_subdirectories(path);\n+\t\tif (safe_create_leading_directories(path))\n+\t\t\treturn;\n \t\tif (!try_create_file(path, mode, buf, size))\n \t\t\treturn;\n \t}\n@@ -1643,7 +1626,7 @@ static void create_one_file(const char *\n \n static void create_file(struct patch *patch)\n {\n-\tconst char *path = patch->new_name;\n+\tchar *path = patch->new_name;\n \tunsigned mode = patch->new_mode;\n \tunsigned long size = patch->resultsize;\n \tchar *buf = patch->result;\n-- \n1.1.5\n"}]}