diff options
| author | schu <schu-github@schulog.org> | 2011-06-09 19:51:33 +0200 |
|---|---|---|
| committer | schu <schu-github@schulog.org> | 2011-07-06 12:25:27 +0200 |
| commit | 42b3a460976757dbe7c4755fd60c3f542a9fb1e2 (patch) | |
| tree | 30ac890b60414c18f014b03366b4a2353af66eab /src/fileops.c | |
| parent | e190da78f373511ca999d32f66115bbc75705abf (diff) | |
| download | libgit2-42b3a460976757dbe7c4755fd60c3f542a9fb1e2.tar.gz | |
fileops: add git_futils_rmdir_recurs()
git_futils_rmdir_recurs() shall remove the given directory and all
subdirectories. This happens only if the directories are empty.
Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c index edde3aa46..afca0329f 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -301,6 +301,31 @@ int git_futils_mkdir_r(const char *path, int mode) return GIT_SUCCESS; } +static int _rmdir_recurs_cb(void *GIT_UNUSED(nil), char *path) +{ + int error = GIT_SUCCESS; + + error = git_futils_isdir(path); + if (error == GIT_SUCCESS) { + size_t root_size = strlen(path); + + if ((error = git_futils_direach(path, GIT_PATH_MAX, _rmdir_recurs_cb, NULL)) < GIT_SUCCESS) + return git__rethrow(error, "Failed to remove directory `%s`", path); + + path[root_size] = '\0'; + return p_rmdir(path); + } + + return git__rethrow(error, "Failed to remove directory. `%s` is not a directory", path); +} + +int git_futils_rmdir_recurs(const char *path) +{ + char p[GIT_PATH_MAX]; + strncpy(p, path, GIT_PATH_MAX); + return _rmdir_recurs_cb(NULL, p); +} + int git_futils_cmp_path(const char *name1, int len1, int isdir1, const char *name2, int len2, int isdir2) { |
