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>

Jonathan Nieder committed Jul 16, 2018 at 23:53 UTC 3c426eccc29e38301774e90adeea336642826b0c
1 file changed +6 -3
builtin/gc.c
+6 -3
@@ -442,6 +442,7 @@ static int report_last_gc_error(void)
442 {
443 struct strbuf sb = STRBUF_INIT;
444 int ret = 0;
445 + ssize_t len;
446 struct stat st;
447 char *gc_log_path = git_pathdup("gc.log");
448
@@ -449,15 +450,17 @@ static int report_last_gc_error(void)
450 if (errno == ENOENT)
451 goto done;
452
452 - ret = error_errno(_("Can't stat %s"), gc_log_path);
453 + ret = error_errno(_("cannot stat '%s'"), gc_log_path);
454 goto done;
455 }
456
457 if (st.st_mtime < gc_log_expire_time)
458 goto done;
459
459 - ret = strbuf_read_file(&sb, gc_log_path, 0);
460 - if (ret > 0)
460 + len = strbuf_read_file(&sb, gc_log_path, 0);
461 + if (len < 0)
462 + ret = error_errno(_("cannot read '%s'"), gc_log_path);
463 + else if (len > 0)
464 ret = error(_("The last gc run reported the following. "
465 "Please correct the root cause\n"
466 "and remove %s.\n"