| 161 | } |
| 162 | |
| 163 | static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, |
| 164 | int dry_run, int quiet, int *dir_gone) |
| 165 | { |
| 166 | DIR *dir; |
| 167 | struct strbuf quoted = STRBUF_INIT; |
| 168 | struct strbuf realpath = STRBUF_INIT; |
| 169 | struct strbuf real_ocwd = STRBUF_INIT; |
| 170 | struct dirent *e; |
| 171 | int res = 0, ret = 0, gone = 1, original_len = path->len, len; |
| 172 | struct string_list dels = STRING_LIST_INIT_DUP; |
| 173 | |
| 174 | *dir_gone = 1; |
| 175 | |
| 176 | if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) && |
| 177 | is_nonbare_repository_dir(path)) { |
| 178 | if (!quiet) { |
| 179 | quote_path(path->buf, prefix, "ed, 0); |
| 180 | printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir), |
| 181 | quoted.buf); |
| 182 | } |
| 183 | |
| 184 | *dir_gone = 0; |
| 185 | goto out; |
| 186 | } |
| 187 | |
| 188 | dir = opendir(path->buf); |
| 189 | if (!dir) { |
| 190 | /* an empty dir could be removed even if it is unreadble */ |
| 191 | res = dry_run ? 0 : rmdir(path->buf); |
| 192 | if (res) { |
| 193 | int saved_errno = errno; |
| 194 | quote_path(path->buf, prefix, "ed, 0); |
| 195 | errno = saved_errno; |
| 196 | warning_errno(_(msg_warn_remove_failed), quoted.buf); |
| 197 | *dir_gone = 0; |
| 198 | } |
| 199 | ret = res; |
| 200 | goto out; |
| 201 | } |
| 202 | |
| 203 | strbuf_complete(path, '/'); |
| 204 | |
| 205 | len = path->len; |
| 206 | while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) { |
| 207 | struct stat st; |
| 208 | |
| 209 | strbuf_setlen(path, len); |
| 210 | strbuf_addstr(path, e->d_name); |
| 211 | if (lstat(path->buf, &st)) |
| 212 | warning_errno(_(msg_warn_lstat_failed), path->buf); |
| 213 | else if (S_ISDIR(st.st_mode)) { |
| 214 | if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone)) |
| 215 | ret = 1; |
| 216 | if (gone) { |
| 217 | quote_path(path->buf, prefix, "ed, 0); |
| 218 | string_list_append(&dels, quoted.buf); |
| 219 | } else |
| 220 | *dir_gone = 0; |
no test coverage detected