Nicer error messages in case saving an object to db goes wrong
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Petr Baudis committed
Nov 9, 2006 at 13:52 UTC
916d081bbaa40617643b09b6dc9c6760993cf6ed
1 file changed
+12
-9
sha1_file.c
+12
-9
@@ -1420,8 +1420,7 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
1420
unlink(tmpfile);
1421
if (ret) {
1422
if (ret != EEXIST) {
1423
- fprintf(stderr, "unable to write sha1 filename %s: %s\n", filename, strerror(ret));
1424
- return -1;
1423
+ return error("unable to write sha1 filename %s: %s\n", filename, strerror(ret));
1424
}
1425
/* FIXME!!! Collision check here ? */
1426
}
@@ -1531,16 +1530,17 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
1530
}
1531
1532
if (errno != ENOENT) {
1534
- fprintf(stderr, "sha1 file %s: %s\n", filename, strerror(errno));
1535
- return -1;
1533
+ return error("sha1 file %s: %s\n", filename, strerror(errno));
1534
}
1535
1536
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
1537
1538
fd = mkstemp(tmpfile);
1539
if (fd < 0) {
1542
- fprintf(stderr, "unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
1543
- return -1;
1540
+ if (errno == EPERM)
1541
+ return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
1542
+ else
1543
+ return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
1544
}
1545
1546
/* Set it up */
@@ -1655,9 +1655,12 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
1655
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
1656
1657
local = mkstemp(tmpfile);
1658
- if (local < 0)
1659
- return error("Couldn't open %s for %s",
1660
- tmpfile, sha1_to_hex(sha1));
1658
+ if (local < 0) {
1659
+ if (errno == EPERM)
1660
+ return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
1661
+ else
1662
+ return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
1663
+ }
1664
1665
memset(&stream, 0, sizeof(stream));
1666