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>
This commit is contained in:
Petr Baudis 2006-11-09 13:52:05 +01:00 коммит произвёл Junio C Hamano
Родитель 0623421b0b
Коммит 916d081bba
1 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

@ -1420,8 +1420,7 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
unlink(tmpfile); unlink(tmpfile);
if (ret) { if (ret) {
if (ret != EEXIST) { if (ret != EEXIST) {
fprintf(stderr, "unable to write sha1 filename %s: %s\n", filename, strerror(ret)); return error("unable to write sha1 filename %s: %s\n", filename, strerror(ret));
return -1;
} }
/* FIXME!!! Collision check here ? */ /* FIXME!!! Collision check here ? */
} }
@ -1531,16 +1530,17 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
} }
if (errno != ENOENT) { if (errno != ENOENT) {
fprintf(stderr, "sha1 file %s: %s\n", filename, strerror(errno)); return error("sha1 file %s: %s\n", filename, strerror(errno));
return -1;
} }
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory()); snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
fd = mkstemp(tmpfile); fd = mkstemp(tmpfile);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno)); if (errno == EPERM)
return -1; 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 */ /* Set it up */
@ -1655,9 +1655,12 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory()); snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
local = mkstemp(tmpfile); local = mkstemp(tmpfile);
if (local < 0) if (local < 0) {
return error("Couldn't open %s for %s", if (errno == EPERM)
tmpfile, sha1_to_hex(sha1)); 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)); memset(&stream, 0, sizeof(stream));