Thread (6 messages) flat view 6 messages, 3 authors, 2021-01-14
STALE2036d

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

From: Christian Couder <hidden>
Date: 2021-01-14 15:51:39
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
Suggested-by: Taylor Blau <redacted>
Signed-off-by: Christian Couder <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help