git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 6/8] commit-graph verify: detect inability to read the graph

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 25, 2019, 12:08 UTC
Message-ID
<20190325120834.15529-7-avarab@gmail.com>
In-Reply-To
<20190314214740.23360-1-avarab@gmail.com>

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>
---
 builtin/commit-graph.c  | 4 +++-
 t/t5318-commit-graph.sh | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 8196fdbe9c..537fdfd0f0 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -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);
 
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index 71d775e313..1cb0355c7e 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -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 &&
-- 
2.21.0.360.g471c308f928
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 28 of 36 in “commit-graph: segfault & other fixes for broken graphs”
  1. 0/8 commit-graph: segfault & other fixes for broken graphsÆvar Arnfjörð Bjarmason, Feb 21, 2019
  2. 1/8 commit-graph tests: split up corrupt_graph_and_verify()Ævar Arnfjörð Bjarmason, Feb 21, 2019
  3. 2/8 commit-graph tests: test a graph that's too smallÆvar Arnfjörð Bjarmason, Feb 21, 2019
  4. 3/8 commit-graph: fix segfault on e.g. "git status"Ævar Arnfjörð Bjarmason, Feb 21, 2019
  5. 4/8 commit-graph: don't early exit(1) on e.g. "git status"Ævar Arnfjörð Bjarmason, Feb 21, 2019
  6. 6/8 commit-graph verify: detect inability to read the graphÆvar Arnfjörð Bjarmason, Feb 21, 2019
  7. SZEDER GáborFeb 21, 2019
  8. 5/8 commit-graph: don't pass filename to load_commit_graph_one_fd_st()Ævar Arnfjörð Bjarmason, Feb 21, 2019
  9. 7/8 commit-graph write: don't die if the existing graph is corruptÆvar Arnfjörð Bjarmason, Feb 21, 2019
  10. Junio C HamanoFeb 22, 2019
  11. Eric SunshineFeb 23, 2019
  12. 8/8 commit-graph: improve & i18n error messagesÆvar Arnfjörð Bjarmason, Feb 21, 2019
  13. 0/8 commit-graph: segfault & other fixes for broken graphsÆvar Arnfjörð Bjarmason, Mar 14, 2019
  14. Eric SunshineMar 15, 2019
  15. Ævar Arnfjörð BjarmasonMar 15, 2019
  16. 0/8 commit-graph: segfault & other fixes for broken graphsÆvar Arnfjörð Bjarmason, Mar 25, 2019
  17. 1/8 commit-graph tests: split up corrupt_graph_and_verify()Ævar Arnfjörð Bjarmason, Mar 25, 2019
  18. 2/8 commit-graph tests: test a graph that's too smallÆvar Arnfjörð Bjarmason, Mar 25, 2019
  19. 3/8 commit-graph: fix segfault on e.g. "git status"Ævar Arnfjörð Bjarmason, Mar 25, 2019
  20. 4/8 commit-graph: don't early exit(1) on e.g. "git status"Ævar Arnfjörð Bjarmason, Mar 25, 2019
  21. Ævar Arnfjörð BjarmasonApr 27, 2019
  22. Derrick StoleeApr 29, 2019
  23. Ævar Arnfjörð BjarmasonApr 29, 2019
  24. Jeff KingMay 1, 2019
  25. 5/8 commit-graph: don't pass filename to load_commit_graph_one_fd_st()Ævar Arnfjörð Bjarmason, Mar 25, 2019
  26. 8/8 commit-graph: improve & i18n error messagesÆvar Arnfjörð Bjarmason, Mar 25, 2019
  27. 7/8 commit-graph write: don't die if the existing graph is corruptÆvar Arnfjörð Bjarmason, Mar 25, 2019
  28. 6/8 commit-graph verify: detect inability to read the graphÆvar Arnfjörð Bjarmason, Mar 25, 2019
  29. 1/8 commit-graph tests: split up corrupt_graph_and_verify()Ævar Arnfjörð Bjarmason, Mar 14, 2019
  30. 2/8 commit-graph tests: test a graph that's too smallÆvar Arnfjörð Bjarmason, Mar 14, 2019
  31. 3/8 commit-graph: fix segfault on e.g. "git status"Ævar Arnfjörð Bjarmason, Mar 14, 2019
  32. 5/8 commit-graph: don't pass filename to load_commit_graph_one_fd_st()Ævar Arnfjörð Bjarmason, Mar 14, 2019
  33. 4/8 commit-graph: don't early exit(1) on e.g. "git status"Ævar Arnfjörð Bjarmason, Mar 14, 2019
  34. 6/8 commit-graph verify: detect inability to read the graphÆvar Arnfjörð Bjarmason, Mar 14, 2019
  35. 7/8 commit-graph write: don't die if the existing graph is corruptÆvar Arnfjörð Bjarmason, Mar 14, 2019
  36. 8/8 commit-graph: improve & i18n error messagesÆvar Arnfjörð Bjarmason, Mar 14, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.