commit-graph verify: detect inability to read the graph
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 25 Mar 2019 12:08:32 +0000 (13:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Apr 2019 03:14:50 +0000 (12:14 +0900)
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>
builtin/commit-graph.c
t/t5318-commit-graph.sh
index 8196fdbe9cfac2573ffcbf1435e4fdb6933c64b5..537fdfd0f0759e8cce2303af5a197ae77b2b879b 100644 (file)
@@ -62,8 +62,10 @@ static int graph_verify(int argc, const char **argv)
 
        graph_name = get_commit_graph_filename(opts.obj_dir);
        open_ok = open_commit_graph(graph_name, &fd, &st);
-       if (!open_ok)
+       if (!open_ok && errno == ENOENT)
                return 0;
+       if (!open_ok)
+               die_errno(_("Could not open commit-graph '%s'"), graph_name);
        graph = load_commit_graph_one_fd_st(fd, &st);
        FREE_AND_NULL(graph_name);
 
index 0d012f55e559e83823ff27235f60a83b1ba4c5fd..4601732b99677c05a04bbc5a40d59529bbae86c5 100755 (executable)
@@ -400,6 +400,12 @@ corrupt_graph_and_verify() {
 
 }
 
+test_expect_success POSIXPERM,SANITY 'detect permission problem' '
+       corrupt_graph_setup &&
+       chmod 000 $objdir/info/commit-graph &&
+       corrupt_graph_verify "Could not open"
+'
+
 test_expect_success 'detect too small' '
        corrupt_graph_setup &&
        echo "a small graph" >$objdir/info/commit-graph &&