diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2011-07-03 22:27:05 +0200 |
|---|---|---|
| committer | schu <schu-github@schulog.org> | 2011-07-06 12:25:27 +0200 |
| commit | 1b938a58267f0a11240f0e7da7233607c6b78a2d (patch) | |
| tree | 1d4188ac05bfb16bbee7945a593a428fdc4cb743 /src/fileops.c | |
| parent | 1ee5fd903d00930aab08edecc6b409a34761cf7e (diff) | |
| download | libgit2-1b938a58267f0a11240f0e7da7233607c6b78a2d.tar.gz | |
Remove duplicated recursive directory removal related code
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/fileops.c b/src/fileops.c index ab3f43cc5..9f3a65d27 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -301,7 +301,7 @@ int git_futils_mkdir_r(const char *path, int mode) return GIT_SUCCESS; } -static int _rmdir_recurs_cb(void *GIT_UNUSED(nil), char *path) +static int _rmdir_recurs_foreach(void *force_removal_of_non_empty_directory, char *path) { int error = GIT_SUCCESS; @@ -311,21 +311,24 @@ static int _rmdir_recurs_cb(void *GIT_UNUSED(nil), char *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) + if ((error = git_futils_direach(path, GIT_PATH_MAX, _rmdir_recurs_foreach, force_removal_of_non_empty_directory)) < 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); + if (*(int *)(force_removal_of_non_empty_directory)) + return p_unlink(path); + else + return git__rethrow(error, "Failed to remove directory. `%s` is not a directory", path); } -int git_futils_rmdir_recurs(const char *path) +int git_futils_rmdir_recurs(const char *path, int force_removal_of_non_empty_directory) { char p[GIT_PATH_MAX]; strncpy(p, path, GIT_PATH_MAX); - return _rmdir_recurs_cb(NULL, p); + return _rmdir_recurs_foreach(&force_removal_of_non_empty_directory, p); } int git_futils_cmp_path(const char *name1, int len1, int isdir1, |
