summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-12-19 22:50:20 +0200
committerVicent Marti <tanoku@gmail.com>2010-12-19 22:50:20 +0200
commit40c44d2fb63dbe484824c9dbc7c098c797ad10a1 (patch)
treecd26714f775a4ba52e8b3160d46364dc3a1e8461 /src/fileops.c
parentfe93dabeef1f2757e73757bb2ec2dd3c912325a8 (diff)
downloadlibgit2-40c44d2fb63dbe484824c9dbc7c098c797ad10a1.tar.gz
Fix issues in repository initialization
Implemented recursive directory creation Fix style issues Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 97b2f0739..a25796a7b 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -313,13 +313,30 @@ int gitfo_dirent(
int gitfo_mkdir_recurs(const char *path, int mode)
{
- //TODO: Implement recursive building of the parent tree structure (This would have to work on both Linux and Windows).
int error;
+ char *pp, *sp;
+ char *path_copy = git__strdup(path);
- error = gitfo_mkdir(path, mode);
+ if (path_copy == NULL)
+ return GIT_ENOMEM;
- if (errno == EEXIST)
- return GIT_SUCCESS;
+ error = GIT_SUCCESS;
+ pp = path_copy;
+
+ while (error == 0 && (sp = strchr(pp, '/')) != 0) {
+ if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) {
+ *sp = 0;
+ error = gitfo_mkdir(path_copy, mode);
+ *sp = '/';
+ }
+
+ pp = sp + 1;
+ }
- return error;
-} \ No newline at end of file
+ if (*(pp - 1) != '/' && error == GIT_SUCCESS)
+ error = gitfo_mkdir(path, mode);
+
+ free(path_copy);
+ return error;
+
+}