clean: use warning_errno() when appropriate

All these warning() calls are preceded by a system call. Report the actual error to help the user understand why we fail to remove something. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Feb 14, 2017 at 16:54 UTC cccf97d6ca90fc06ba7680cbbac440763f3e9831
1 file changed +12 -4
builtin/clean.c
+12 -4
@@ -174,8 +174,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
174 /* an empty dir could be removed even if it is unreadble */
175 res = dry_run ? 0 : rmdir(path->buf);
176 if (res) {
177 + int saved_errno = errno;
178 quote_path_relative(path->buf, prefix, &quoted);
178 - warning(_(msg_warn_remove_failed), quoted.buf);
179 + errno = saved_errno;
180 + warning_errno(_(msg_warn_remove_failed), quoted.buf);
181 *dir_gone = 0;
182 }
183 return res;
@@ -208,8 +210,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
210 quote_path_relative(path->buf, prefix, &quoted);
211 string_list_append(&dels, quoted.buf);
212 } else {
213 + int saved_errno = errno;
214 quote_path_relative(path->buf, prefix, &quoted);
212 - warning(_(msg_warn_remove_failed), quoted.buf);
215 + errno = saved_errno;
216 + warning_errno(_(msg_warn_remove_failed), quoted.buf);
217 *dir_gone = 0;
218 ret = 1;
219 }
@@ -230,8 +234,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
234 if (!res)
235 *dir_gone = 1;
236 else {
237 + int saved_errno = errno;
238 quote_path_relative(path->buf, prefix, &quoted);
234 - warning(_(msg_warn_remove_failed), quoted.buf);
239 + errno = saved_errno;
240 + warning_errno(_(msg_warn_remove_failed), quoted.buf);
241 *dir_gone = 0;
242 ret = 1;
243 }
@@ -981,8 +987,10 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
987 } else {
988 res = dry_run ? 0 : unlink(abs_path.buf);
989 if (res) {
990 + int saved_errno = errno;
991 qname = quote_path_relative(item->string, NULL, &buf);
985 - warning(_(msg_warn_remove_failed), qname);
992 + errno = saved_errno;
993 + warning_errno(_(msg_warn_remove_failed), qname);
994 errors++;
995 } else if (!quiet) {
996 qname = quote_path_relative(item->string, NULL, &buf);