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

[PATCH v2 3/3] pack-write: die on error in write_promisor_file()

From
Christian Couder <christian.couder@gmail.com>
Date
Jan 14, 2021, 15:50 UTC
Message-ID
<20210114155016.3005932-4-chriscool@tuxfamily.org>
In-Reply-To
<20210114155016.3005932-1-chriscool@tuxfamily.org>

write_promisor_file() already uses xfopen(), so it would die if the file cannot be opened for writing. To be consistent with this behavior and not overlook issues, let's also die if there are errors when we are actually writing to the file.

Suggested-by: Jeff King <peff@peff.net>
Suggested-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 pack-write.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index db3ff9980f..e9bb3fd949 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -371,11 +371,15 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
 
 void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)
 {
-	int i;
+	int i, err;
 	FILE *output = xfopen(promisor_name, "w");
 
 	for (i = 0; i < nr_sought; i++)
 		fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
 			sought[i]->name);
-	fclose(output);
+
+	err = ferror(output);
+	err |= fclose(output);
+	if (err)
+		die(_("could not write '%s' promisor file"), promisor_name);
 }
-- 
2.30.0.83.g36fd80b35a.dirty
Previous: Christian CouderNext: Taylor Blau
Message 4 of 6 in “Refactor writing promisor file”
  1. 0/3 Refactor writing promisor fileChristian Couder, Jan 14, 2021
  2. 1/3 fetch-pack: rename helper to create_promisor_file()Christian Couder, Jan 14, 2021
  3. 2/3 fetch-pack: refactor writing promisor fileChristian Couder, Jan 14, 2021
  4. 3/3 pack-write: die on error in write_promisor_file()Christian Couder, Jan 14, 2021
  5. Taylor BlauJan 14, 2021
  6. Jeff KingJan 14, 2021

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.