X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=sha1_file.c;h=fd6096f4170f2db58320dc7d7e16f25b6c7fd0c9;hb=a7336ae514738f159dad314d6674961427f043a6;hp=bbb749c561ebfe6cff8240f99b8902e526dda368;hpb=f17a1b1bec5cef1d39521aac92f94858acda6433;p=git.git diff --git a/sha1_file.c b/sha1_file.c index bbb749c5..fd6096f4 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -130,6 +130,25 @@ char *git_path(const char *fmt, ...) return ret; } +int safe_create_leading_directories(char *path) +{ + char *pos = path; + + while (pos) { + pos = strchr(pos, '/'); + if (!pos) + break; + *pos = 0; + if (mkdir(path, 0777) < 0) + if (errno != EEXIST) { + *pos = '/'; + return -1; + } + *pos++ = '/'; + } + return 0; +} + int get_sha1(const char *str, unsigned char *sha1) { static const char *prefix[] = { @@ -463,6 +482,7 @@ static void prepare_packed_git_one(char *objdir) p->next = packed_git; packed_git = p; } + closedir(dir); } void prepare_packed_git(void)