summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2011-07-06 06:54:11 -0700
committerVicent Martí <tanoku@gmail.com>2011-07-06 06:54:11 -0700
commitb8e2db5f94d2a5d93bb4a328cbff5c26f65a5ebb (patch)
tree1d4188ac05bfb16bbee7945a593a428fdc4cb743 /src/fileops.c
parente1bf24c86221fb412df52340ef2faa65c816c7bf (diff)
parent1b938a58267f0a11240f0e7da7233607c6b78a2d (diff)
downloadlibgit2-b8e2db5f94d2a5d93bb4a328cbff5c26f65a5ebb.tar.gz
Merge pull request #303 from schu/ref-rename
reference_rename: git compliant reference renaming v2
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 52aeb41a3..9f3a65d27 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -231,13 +231,8 @@ int git_futils_direach(
size_t de_len;
int result;
- /* always skip '.' and '..' */
- if (de->d_name[0] == '.') {
- if (de->d_name[1] == '\0')
- continue;
- if (de->d_name[1] == '.' && de->d_name[2] == '\0')
- continue;
- }
+ if (is_dot_or_dotdot(de->d_name))
+ continue;
de_len = strlen(de->d_name);
if (path_sz < wd_len + de_len + 1) {
@@ -306,6 +301,36 @@ int git_futils_mkdir_r(const char *path, int mode)
return GIT_SUCCESS;
}
+static int _rmdir_recurs_foreach(void *force_removal_of_non_empty_directory, char *path)
+{
+ int error = GIT_SUCCESS;
+
+ GIT_UNUSED_ARG(nil)
+
+ 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_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);
+ }
+
+ 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 force_removal_of_non_empty_directory)
+{
+ char p[GIT_PATH_MAX];
+ strncpy(p, path, GIT_PATH_MAX);
+ return _rmdir_recurs_foreach(&force_removal_of_non_empty_directory, p);
+}
+
int git_futils_cmp_path(const char *name1, int len1, int isdir1,
const char *name2, int len2, int isdir2)
{