All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Baudis <pasky@suse.cz>
To: Junio C Hamano <junkio@cox.net>
Cc: <git@vger.kernel.org>
Subject: [PATCH] Nicer error messages in case saving an object to db goes wrong
Date: Thu, 09 Nov 2006 13:52:05 +0100	[thread overview]
Message-ID: <20061109125205.25131.50211.stgit@machine.or.cz> (raw)

Currently the error e.g. when pushing to a read-only repository is quite
confusing, this attempts to clean it up, unifies error reporting between
various object writers and uses error() on couple more places.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---

 sha1_file.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 6ea59b5..09456d2 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1455,8 +1455,7 @@ int move_temp_to_file(const char *tmpfil
 	unlink(tmpfile);
 	if (ret) {
 		if (ret != EEXIST) {
-			fprintf(stderr, "unable to write sha1 filename %s: %s\n", filename, strerror(ret));
-			return -1;
+			return error("unable to write sha1 filename %s: %s\n", filename, strerror(ret));
 		}
 		/* FIXME!!! Collision check here ? */
 	}
@@ -1566,16 +1565,17 @@ int write_sha1_file(void *buf, unsigned
 	}
 
 	if (errno != ENOENT) {
-		fprintf(stderr, "sha1 file %s: %s\n", filename, strerror(errno));
-		return -1;
+		return error("sha1 file %s: %s\n", filename, strerror(errno));
 	}
 
 	snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
 
 	fd = mkstemp(tmpfile);
 	if (fd < 0) {
-		fprintf(stderr, "unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
-		return -1;
+		if (errno == EPERM)
+			return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
+		else
+			return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
 	}
 
 	/* Set it up */
@@ -1690,9 +1690,12 @@ int write_sha1_from_fd(const unsigned ch
 	snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
 
 	local = mkstemp(tmpfile);
-	if (local < 0)
-		return error("Couldn't open %s for %s",
-			     tmpfile, sha1_to_hex(sha1));
+	if (local < 0) {
+		if (errno == EPERM)
+			return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
+		else
+			return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
+	}
 
 	memset(&stream, 0, sizeof(stream));

                 reply	other threads:[~2006-11-09 12:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=20061109125205.25131.50211.stgit@machine.or.cz \
    --to=pasky@suse.cz \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.