summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2014-04-09 12:43:27 +0200
committerVicent Marti <tanoku@gmail.com>2014-04-09 12:43:27 +0200
commitc3dcbe8488c6240392e8a5d7553bbffcb0f94ef0 (patch)
tree420715f61601a1863264f9ea9a32d8ccde096b57
parentc031129510a4bfaef9b2563de3a8ae82d04f5b6c (diff)
downloadlibgit2-vmg/state-cleanup.tar.gz
Rewrite `git_repository__cleanup_files`vmg/state-cleanup
-rw-r--r--src/repository.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/repository.c b/src/repository.c
index 37aba4b81..6b2705bfa 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1955,26 +1955,32 @@ int git_repository_state(git_repository *repo)
return state;
}
-int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len)
+int git_repository__cleanup_files(
+ git_repository *repo, const char *files[], size_t files_len)
{
- git_buf path = GIT_BUF_INIT;
+ git_buf buf = GIT_BUF_INIT;
size_t i;
- int error = 0;
+ int error;
- for (i = 0; i < files_len; ++i) {
- git_buf_clear(&path);
+ for (error = 0, i = 0; !error && i < files_len; ++i) {
+ const char *path;
- if ((error = git_buf_joinpath(&path, repo->path_repository, files[i])) < 0 ||
- (git_path_isfile(git_buf_cstr(&path)) &&
- (error = p_unlink(git_buf_cstr(&path))) < 0) ||
- (git_path_isdir(git_buf_cstr(&path)) &&
- (error = git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS)) < 0))
- goto done;
- }
+ if (git_buf_joinpath(&buf, repo->path_repository, files[i]) < 0)
+ return -1;
-done:
- git_buf_free(&path);
+ path = git_buf_cstr(&buf);
+
+ if (git_path_isfile(path)) {
+ error = p_unlink(path);
+ } else if (git_path_isdir(path)) {
+ error = git_futils_rmdir_r(path, NULL,
+ GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
+ }
+
+ git_buf_clear(&buf);
+ }
+ git_buf_free(&buf);
return error;
}