git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Christian Couder <chriscool@tuxfamily.org>,
	Jonathan Tan <jonathantanmy@google.com>,
	Jeff King <peff@peff.net>, Taylor Blau <me@ttaylorr.com>
Subject: [PATCH v2 3/3] pack-write: die on error in write_promisor_file()
Date: Thu, 14 Jan 2021 16:50:16 +0100	[thread overview]
Message-ID: <20210114155016.3005932-4-chriscool@tuxfamily.org> (raw)
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


  parent reply	other threads:[~2021-01-14 15:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14 15:50 [PATCH v2 0/3] Refactor writing promisor file Christian Couder
2021-01-14 15:50 ` [PATCH v2 1/3] fetch-pack: rename helper to create_promisor_file() Christian Couder
2021-01-14 15:50 ` [PATCH v2 2/3] fetch-pack: refactor writing promisor file Christian Couder
2021-01-14 15:50 ` Christian Couder [this message]
2021-01-14 17:23 ` [PATCH v2 0/3] Refactor " Taylor Blau
2021-01-14 20:11 ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210114155016.3005932-4-chriscool@tuxfamily.org \
    --to=christian.couder@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).