summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2013-03-01 11:07:53 -0500
committerJameson Miller <jamill@microsoft.com>2013-03-01 14:56:09 -0500
commit926acbcf8ed80a69ab82f3d14e90dabeca9af07d (patch)
tree550f4e6314038033bbbced49b5934e1706405278 /src/fileops.c
parentcc427158d4fafa26e3d2d9f69da51a1a8d8a92d4 (diff)
downloadlibgit2-926acbcf8ed80a69ab82f3d14e90dabeca9af07d.tar.gz
Clone should not delete directories it did not create
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 3531e75b8..6429e55b4 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -519,6 +519,41 @@ int git_futils_rmdir_r(
return error;
}
+int git_futils_cleanupdir_r(const char *path)
+{
+ int error;
+ git_buf fullpath = GIT_BUF_INIT;
+ futils__rmdir_data data;
+
+ if ((error = git_buf_put(&fullpath, path, strlen(path)) < 0))
+ goto clean_up;
+
+ data.base = "";
+ data.baselen = 0;
+ data.flags = GIT_RMDIR_REMOVE_FILES;
+ data.error = 0;
+
+ if (!git_path_exists(path)) {
+ giterr_set(GITERR_OS, "Path does not exist: %s" , path);
+ error = GIT_ERROR;
+ goto clean_up;
+ }
+
+ if (!git_path_isdir(path)) {
+ giterr_set(GITERR_OS, "Path is not a directory: %s" , path);
+ error = GIT_ERROR;
+ goto clean_up;
+ }
+
+ error = git_path_direach(&fullpath, futils__rmdir_recurs_foreach, &data);
+ if (error == GIT_EUSER)
+ error = data.error;
+
+clean_up:
+ git_buf_free(&fullpath);
+ return error;
+}
+
int git_futils_find_system_file(git_buf *path, const char *filename)
{
#ifdef GIT_WIN32