diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-12-19 22:50:20 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-12-19 22:50:20 +0200 |
| commit | 40c44d2fb63dbe484824c9dbc7c098c797ad10a1 (patch) | |
| tree | cd26714f775a4ba52e8b3160d46364dc3a1e8461 /src/fileops.c | |
| parent | fe93dabeef1f2757e73757bb2ec2dd3c912325a8 (diff) | |
| download | libgit2-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.c | 29 |
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; + +} |
