Skip to content

Commit 7c99bc2

Browse files
chriscoolgitster
authored andcommitted
pack-write: die on error in write_promisor_file()
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 <[email protected]> Suggested-by: Taylor Blau <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33add2a commit 7c99bc2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pack-write.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,15 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
371371

372372
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)
373373
{
374-
int i;
374+
int i, err;
375375
FILE *output = xfopen(promisor_name, "w");
376376

377377
for (i = 0; i < nr_sought; i++)
378378
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
379379
sought[i]->name);
380-
fclose(output);
380+
381+
err = ferror(output);
382+
err |= fclose(output);
383+
if (err)
384+
die(_("could not write '%s' promisor file"), promisor_name);
381385
}

0 commit comments

Comments
 (0)