{"thread":{"id":"43188","subject":"[PATCH] Nicer error messages in case saving an object to db goes wrong","startedAt":"2006-11-09T12:52:05Z","lastAt":"2006-11-09T12:52:05Z","messageCount":1,"participants":["Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"294002","messageId":"20061109125205.25131.50211.stgit@machine.or.cz","threadId":"43188","inReplyTo":null,"subject":"[PATCH] Nicer error messages in case saving an object to db goes wrong","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-11-09T12:52:05Z","receivedAt":"2006-11-09T12:52:05Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Currently the error e.g. when pushing to a read-only repository is quite\nconfusing, this attempts to clean it up, unifies error reporting between\nvarious object writers and uses error() on couple more places.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n sha1_file.c |   21 ++++++++++++---------\n 1 files changed, 12 insertions(+), 9 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 6ea59b5..09456d2 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1455,8 +1455,7 @@ int move_temp_to_file(const char *tmpfil\n \tunlink(tmpfile);\n \tif (ret) {\n \t\tif (ret != EEXIST) {\n-\t\t\tfprintf(stderr, \"unable to write sha1 filename %s: %s\\n\", filename, strerror(ret));\n-\t\t\treturn -1;\n+\t\t\treturn error(\"unable to write sha1 filename %s: %s\\n\", filename, strerror(ret));\n \t\t}\n \t\t/* FIXME!!! Collision check here ? */\n \t}\n@@ -1566,16 +1565,17 @@ int write_sha1_file(void *buf, unsigned\n \t}\n \n \tif (errno != ENOENT) {\n-\t\tfprintf(stderr, \"sha1 file %s: %s\\n\", filename, strerror(errno));\n-\t\treturn -1;\n+\t\treturn error(\"sha1 file %s: %s\\n\", filename, strerror(errno));\n \t}\n \n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s/obj_XXXXXX\", get_object_directory());\n \n \tfd = mkstemp(tmpfile);\n \tif (fd < 0) {\n-\t\tfprintf(stderr, \"unable to create temporary sha1 filename %s: %s\\n\", tmpfile, strerror(errno));\n-\t\treturn -1;\n+\t\tif (errno == EPERM)\n+\t\t\treturn error(\"insufficient permission for adding an object to repository database %s\\n\", get_object_directory());\n+\t\telse\n+\t\t\treturn error(\"unable to create temporary sha1 filename %s: %s\\n\", tmpfile, strerror(errno));\n \t}\n \n \t/* Set it up */\n@@ -1690,9 +1690,12 @@ int write_sha1_from_fd(const unsigned ch\n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s/obj_XXXXXX\", get_object_directory());\n \n \tlocal = mkstemp(tmpfile);\n-\tif (local < 0)\n-\t\treturn error(\"Couldn't open %s for %s\",\n-\t\t\t     tmpfile, sha1_to_hex(sha1));\n+\tif (local < 0) {\n+\t\tif (errno == EPERM)\n+\t\t\treturn error(\"insufficient permission for adding an object to repository database %s\\n\", get_object_directory());\n+\t\telse\n+\t\t\treturn error(\"unable to create temporary sha1 filename %s: %s\\n\", tmpfile, strerror(errno));\n+\t}\n \n \tmemset(&stream, 0, sizeof(stream));\n"}]}