diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-01-03 21:37:14 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-01-03 21:41:19 +0200 |
| commit | d5f2520413939b114bdb4da95e6b10ee60e67f4c (patch) | |
| tree | 79cb4d1e5791d09fc4944b961993bc5dfe49eb93 /src/fileops.c | |
| parent | e0646b38c7acfcfc1802c987ceaa2c275b4ae226 (diff) | |
| parent | 951d06e4e99d3a750ead21605bc71e78cfd5ab2d (diff) | |
| download | libgit2-d5f2520413939b114bdb4da95e6b10ee60e67f4c.tar.gz | |
Merge branch 'repo-init' of https://github.com/nulltoken/libgit2 into nulltoken-repo-init
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/src/fileops.c b/src/fileops.c index 5d7e92978..68f45c25a 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -1,5 +1,6 @@ #include "common.h" #include "fileops.h" +#include <ctype.h> int gitfo_open(const char *path, int flags) { @@ -311,6 +312,19 @@ int gitfo_dirent( return GIT_SUCCESS; } +#ifdef GIT_WIN32 + +static int is_windows_rooted_path(const char *path) +{ + /* Does the root of the path look like a windows drive ? */ + if (isalpha(path[0]) && (path[1] == ':')) + return GIT_SUCCESS; + + return GIT_ERROR; +} + +#endif + int gitfo_mkdir_recurs(const char *path, int mode) { int error; @@ -320,23 +334,35 @@ int gitfo_mkdir_recurs(const char *path, int mode) if (path_copy == NULL) return GIT_ENOMEM; - error = GIT_SUCCESS; - pp = path_copy; + 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 = '/'; - } +#ifdef GIT_WIN32 - pp = sp + 1; - } + if (!is_windows_rooted_path(pp)) + pp += 2; /* Skip the drive name (eg. C: or D:) */ + +#endif + + while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != 0) { + if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) { + *sp = 0; + error = gitfo_mkdir(path_copy, mode); + + /* Do not choke while trying to recreate an existing directory */ + if (errno == EEXIST) + error = GIT_SUCCESS; + + *sp = '/'; + } + + pp = sp + 1; + } - if (*(pp - 1) != '/' && error == GIT_SUCCESS) - error = gitfo_mkdir(path, mode); + if (*(pp - 1) != '/' && error == GIT_SUCCESS) + error = gitfo_mkdir(path, mode); - free(path_copy); - return error; + free(path_copy); + return error; } |
