summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2018-07-17 06:53:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-17 18:18:07 (GMT)
commit3c426eccc29e38301774e90adeea336642826b0c (patch)
treef725d148f84c020b3c51254c9a3f77d93e300838 /builtin
parent53f9a3e157dbbc901a02ac2c73346d375e24978c (diff)
downloadgit-3c426eccc29e38301774e90adeea336642826b0c.zip
git-3c426eccc29e38301774e90adeea336642826b0c.tar.gz
git-3c426eccc29e38301774e90adeea336642826b0c.tar.bz2
gc: improve handling of errors reading gc.log
A collection of minor error handling fixes: - use an error message in lower case, following the usual style - quote filenames in error messages to make them easier to read and to decrease translation load by matching other 'stat' error messages - check for and report errors from 'read', too - avoid being confused by a gc.log larger than INT_MAX bytes Noticed by code inspection. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/gc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index ccfb1ce..d69fc4c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -442,6 +442,7 @@ static int report_last_gc_error(void)
{
struct strbuf sb = STRBUF_INIT;
int ret = 0;
+ ssize_t len;
struct stat st;
char *gc_log_path = git_pathdup("gc.log");
@@ -449,15 +450,17 @@ static int report_last_gc_error(void)
if (errno == ENOENT)
goto done;
- ret = error_errno(_("Can't stat %s"), gc_log_path);
+ ret = error_errno(_("cannot stat '%s'"), gc_log_path);
goto done;
}
if (st.st_mtime < gc_log_expire_time)
goto done;
- ret = strbuf_read_file(&sb, gc_log_path, 0);
- if (ret > 0)
+ len = strbuf_read_file(&sb, gc_log_path, 0);
+ if (len < 0)
+ ret = error_errno(_("cannot read '%s'"), gc_log_path);
+ else if (len > 0)
ret = error(_("The last gc run reported the following. "
"Please correct the root cause\n"
"and remove %s.\n"