From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2] clean: use warning_errno() when appropriate
Date: Tue, 14 Feb 2017 16:54:49 +0700 [thread overview]
Message-ID: <20170214095449.15585-1-pclouds@gmail.com> (raw)
In-Reply-To: <20170213092702.10462-1-pclouds@gmail.com>
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>
---
v2 dances with errno
builtin/clean.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index d6bc3aaae..3569736f6 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -154,6 +154,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
struct strbuf quoted = STRBUF_INIT;
struct dirent *e;
int res = 0, ret = 0, gone = 1, original_len = path->len, len;
+ int saved_errno;
struct string_list dels = STRING_LIST_INIT_DUP;
*dir_gone = 1;
@@ -173,9 +174,11 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
if (!dir) {
/* an empty dir could be removed even if it is unreadble */
res = dry_run ? 0 : rmdir(path->buf);
+ saved_errno = errno;
if (res) {
quote_path_relative(path->buf, prefix, "ed);
- warning(_(msg_warn_remove_failed), quoted.buf);
+ errno = saved_errno;
+ warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
}
return res;
@@ -204,12 +207,14 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
continue;
} else {
res = dry_run ? 0 : unlink(path->buf);
+ saved_errno = errno;
if (!res) {
quote_path_relative(path->buf, prefix, "ed);
string_list_append(&dels, quoted.buf);
} else {
quote_path_relative(path->buf, prefix, "ed);
- warning(_(msg_warn_remove_failed), quoted.buf);
+ errno = saved_errno;
+ warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
ret = 1;
}
@@ -227,11 +232,13 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
if (*dir_gone) {
res = dry_run ? 0 : rmdir(path->buf);
+ saved_errno = errno;
if (!res)
*dir_gone = 1;
else {
quote_path_relative(path->buf, prefix, "ed);
- warning(_(msg_warn_remove_failed), quoted.buf);
+ errno = saved_errno;
+ warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
ret = 1;
}
@@ -853,7 +860,7 @@ static void interactive_main_loop(void)
int cmd_clean(int argc, const char **argv, const char *prefix)
{
- int i, res;
+ int i, res, saved_errno;
int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, config_set = 0, errors = 0, gone = 1;
int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
@@ -980,9 +987,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
}
} else {
res = dry_run ? 0 : unlink(abs_path.buf);
+ saved_errno = errno;
if (res) {
qname = quote_path_relative(item->string, NULL, &buf);
- warning(_(msg_warn_remove_failed), qname);
+ errno = saved_errno;
+ warning_errno(_(msg_warn_remove_failed), qname);
errors++;
} else if (!quiet) {
qname = quote_path_relative(item->string, NULL, &buf);
--
2.11.0.157.gd943d85
next prev parent reply other threads:[~2017-02-14 9:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-13 9:27 [PATCH] clean: use warning_errno() when appropriate Nguyễn Thái Ngọc Duy
2017-02-13 18:34 ` Junio C Hamano
2017-02-13 19:14 ` Jeff King
2017-02-13 20:38 ` Junio C Hamano
2017-02-13 21:10 ` Jeff King
2017-02-13 21:53 ` Junio C Hamano
2017-02-13 22:22 ` Jeff King
2017-02-13 23:48 ` Junio C Hamano
2017-02-14 9:54 ` Nguyễn Thái Ngọc Duy [this message]
2017-02-14 18:13 ` [PATCH v2] " Junio C Hamano
2017-02-15 0:49 ` Duy Nguyen
2017-02-15 1:28 ` Junio C Hamano
2017-02-15 1:36 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170214095449.15585-1-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).