From 59397b94b11b643ba6120c7b2be9643f8d1022d4 Mon Sep 17 00:00:00 2001 From: KayGau Date: Mon, 10 Jun 2019 16:10:09 +0800 Subject: [PATCH] Fix bug caused by open a file with directory not exist --- batch_fetch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/batch_fetch.c b/batch_fetch.c index 5c8bebca6f5..294bcb4a15c 100644 --- a/batch_fetch.c +++ b/batch_fetch.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ void recursive_mkdir(char *dir_path) pdir[i] = 0; struct stat st = {0}; if(stat(pdir, &st) == -1) { - mkdir(pdir, 0700); + recursive_mkdir(pdir); } mkdir(dir_path, 0700); if(pdir) @@ -158,7 +159,7 @@ int main(int argc, char *argv[]) FILE *out = fopen(obj_file_path, "wb"); fwrite(dest, compressSize, 1, out); fclose(out); - + char *refs_heads_path = malloc(strlen(path) + strlen("/.git/refs/heads/") + strlen(heads_name) + 10); memset(refs_heads_path, 0, strlen(path) + strlen("/.git/refs/heads/") + strlen(heads_name) + 10); strcpy(refs_heads_path, path);