diff options
author | Jameson Miller <jamill@microsoft.com> | 2013-03-01 20:07:53 +0400 |
---|---|---|
committer | Jameson Miller <jamill@microsoft.com> | 2013-03-01 23:56:09 +0400 |
commit | 926acbcf8ed80a69ab82f3d14e90dabeca9af07d (patch) | |
tree | 550f4e6314038033bbbced49b5934e1706405278 /src/fileops.c | |
parent | cc427158d4fafa26e3d2d9f69da51a1a8d8a92d4 (diff) |
Clone should not delete directories it did not create
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 35 |
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 |