Signed-off-by: Rene Scharfe <[email protected]>
---
builtin/clean.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 21a7a32994..733b6d3745 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -151,104 +151,107 @@ static int exclude_cb(const struct option *opt, const
char *arg, int unset)
static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
int dry_run, int quiet, int *dir_gone)
{
DIR *dir;
struct strbuf quoted = STRBUF_INIT;
struct dirent *e;
int res = 0, ret = 0, gone = 1, original_len = path->len, len;
struct string_list dels = STRING_LIST_INIT_DUP;
*dir_gone = 1;
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
is_nonbare_repository_dir(path)) {
if (!quiet) {
quote_path_relative(path->buf, prefix, "ed);
printf(dry_run ? _(msg_would_skip_git_dir) :
_(msg_skip_git_dir),
quoted.buf);
}
*dir_gone = 0;
- return 0;
+ goto out;
}
dir = opendir(path->buf);
if (!dir) {
/* an empty dir could be removed even if it is unreadble */
res = dry_run ? 0 : rmdir(path->buf);
if (res) {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, "ed);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
}
- return res;
+ ret = res;
+ goto out;
}
strbuf_complete(path, '/');
len = path->len;
while ((e = readdir(dir)) != NULL) {
struct stat st;
if (is_dot_or_dotdot(e->d_name))
continue;
strbuf_setlen(path, len);
strbuf_addstr(path, e->d_name);
if (lstat(path->buf, &st))
; /* fall thru */
else if (S_ISDIR(st.st_mode)) {
if (remove_dirs(path, prefix, force_flag, dry_run,
quiet, &gone))
ret = 1;
if (gone) {
quote_path_relative(path->buf, prefix, "ed);
string_list_append(&dels, quoted.buf);
} else
*dir_gone = 0;
continue;
} else {
res = dry_run ? 0 : unlink(path->buf);
if (!res) {
quote_path_relative(path->buf, prefix, "ed);
string_list_append(&dels, quoted.buf);
} else {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, "ed);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed),
quoted.buf);
*dir_gone = 0;
ret = 1;
}
continue;
}
/* path too long, stat fails, or non-directory still exists */
*dir_gone = 0;
ret = 1;
break;
}
closedir(dir);
strbuf_setlen(path, original_len);
if (*dir_gone) {
res = dry_run ? 0 : rmdir(path->buf);
if (!res)
*dir_gone = 1;
else {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, "ed);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
ret = 1;
}
}
if (!*dir_gone && !quiet) {
int i;
for (i = 0; i < dels.nr; i++)
printf(dry_run ? _(msg_would_remove) : _(msg_remove),
dels.items[i].string);
}
+out:
+ strbuf_release("ed);
string_list_clear(&dels, 0);
return ret;
}
--
2.14.1