Skip to content

Commit 916d081

Browse files
Petr BaudisJunio C Hamano
authored andcommitted
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>
1 parent 0623421 commit 916d081

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

sha1_file.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,7 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
14201420
unlink(tmpfile);
14211421
if (ret) {
14221422
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));
14251424
}
14261425
/* FIXME!!! Collision check here ? */
14271426
}
@@ -1531,16 +1530,17 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
15311530
}
15321531

15331532
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));
15361534
}
15371535

15381536
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
15391537

15401538
fd = mkstemp(tmpfile);
15411539
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));
15441544
}
15451545

15461546
/* Set it up */
@@ -1655,9 +1655,12 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
16551655
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
16561656

16571657
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+
}
16611664

16621665
memset(&stream, 0, sizeof(stream));
16631666

0 commit comments

Comments
 (0)