commit-graph verify: detect inability to read the graph
Change "commit-graph verify" to error on open() failures other than ENOENT. As noted in the third paragraph of 283e68c72f ("commit-graph: add 'verify' subcommand", 2018-06-27) and the test it added it's intentional that "commit-graph verify" doesn't error out when the file doesn't exist. But let's not be overly promiscuous in what we accept. If we can't read the file for other reasons, e.g. permission errors, bad file descriptor etc. we'd like to report an error to the user. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 25, 2019 at 13:08 UTC
7b8ce9c673324d55e2b9d8331a796c74559b04c8
2 files changed
+9
-1
builtin/commit-graph.c
+3
-1
@@ -62,8 +62,10 @@ static int graph_verify(int argc, const char **argv)
62
63
graph_name = get_commit_graph_filename(opts.obj_dir);
64
open_ok = open_commit_graph(graph_name, &fd, &st);
65
- if (!open_ok)
65
+ if (!open_ok && errno == ENOENT)
66
return 0;
67
+ if (!open_ok)
68
+ die_errno(_("Could not open commit-graph '%s'"), graph_name);
69
graph = load_commit_graph_one_fd_st(fd, &st);
70
FREE_AND_NULL(graph_name);
71
t/t5318-commit-graph.sh
+6
@@ -400,6 +400,12 @@ corrupt_graph_and_verify() {
400
401
}
402
403
+test_expect_success POSIXPERM,SANITY 'detect permission problem' '
404
+ corrupt_graph_setup &&
405
+ chmod 000 $objdir/info/commit-graph &&
406
+ corrupt_graph_verify "Could not open"
407
+'
408
+
409
test_expect_success 'detect too small' '
410
corrupt_graph_setup &&
411
echo "a small graph" >$objdir/info/commit-graph &&