{"thread":{"id":"6370","subject":"[PATCH] Remove read_or_die in favor of better error messages.","startedAt":"2007-01-14T06:01:49Z","lastAt":"2007-01-14T06:01:49Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"31677","messageId":"20070114060149.GA19249@spearce.org","threadId":"6370","inReplyTo":null,"subject":"[PATCH] Remove read_or_die in favor of better error messages.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-14T06:01:49Z","receivedAt":"2007-01-14T06:01:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Originally I introduced read_or_die for the purpose of reading\nthe pack header and trailer, and I was too lazy to print proper\nerror messages.\n\nLinus Torvalds <torvalds@osdl.org>:\n> For a read error, at the very least you have to say WHICH FILE\n> couldn't be read, because it's usually a matter of some file just\n> being too short, not some system-wide problem.\n\nand of course Linus is right. Make it so.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n cache.h        |    1 -\n sha1_file.c    |    6 ++++--\n write_or_die.c |   12 ------------\n 3 files changed, 4 insertions(+), 15 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex c482c32..620b6a4 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -434,7 +434,6 @@ extern char *git_log_output_encoding;\n \n extern int copy_fd(int ifd, int ofd);\n extern int read_in_full(int fd, void *buf, size_t count);\n-extern void read_or_die(int fd, void *buf, size_t count);\n extern int write_in_full(int fd, const void *buf, size_t count);\n extern void write_or_die(int fd, const void *buf, size_t count);\n extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 2a5be53..1b1c0f7 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -572,7 +572,8 @@ static void open_packed_git(struct packed_git *p)\n \t\tdie(\"cannot set FD_CLOEXEC\");\n \n \t/* Verify we recognize this pack file format. */\n-\tread_or_die(p->pack_fd, &hdr, sizeof(hdr));\n+\tif (read_in_full(p->pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))\n+\t\tdie(\"file %s is far too short to be a packfile\", p->pack_name);\n \tif (hdr.hdr_signature != htonl(PACK_SIGNATURE))\n \t\tdie(\"file %s is not a GIT packfile\", p->pack_name);\n \tif (!pack_version_ok(hdr.hdr_version))\n@@ -588,7 +589,8 @@ static void open_packed_git(struct packed_git *p)\n \t\t\tnum_packed_objects(p));\n \tif (lseek(p->pack_fd, p->pack_size - sizeof(sha1), SEEK_SET) == -1)\n \t\tdie(\"end of packfile %s is unavailable\", p->pack_name);\n-\tread_or_die(p->pack_fd, sha1, sizeof(sha1));\n+\tif (read_in_full(p->pack_fd, sha1, sizeof(sha1)) != sizeof(sha1))\n+\t\tdie(\"packfile %s signature is unavailable\", p->pack_name);\n \tidx_sha1 = ((unsigned char *)p->index_base) + p->index_size - 40;\n \tif (hashcmp(sha1, idx_sha1))\n \t\tdie(\"packfile %s does not match index\", p->pack_name);\ndiff --git a/write_or_die.c b/write_or_die.c\nindex 4e8183e..046e79d 100644\n--- a/write_or_die.c\n+++ b/write_or_die.c\n@@ -17,18 +17,6 @@ int read_in_full(int fd, void *buf, size_t count)\n \treturn total;\n }\n \n-void read_or_die(int fd, void *buf, size_t count)\n-{\n-\tssize_t loaded;\n-\n-\tloaded = read_in_full(fd, buf, count);\n-\tif (loaded != count) {\n-\t\tif (loaded < 0)\n-\t\t\tdie(\"read error (%s)\", strerror(errno));\n-\t\tdie(\"read error: end of file\");\n-\t}\n-}\n-\n int write_in_full(int fd, const void *buf, size_t count)\n {\n \tconst char *p = buf;\n-- \n1.5.0.rc1.g4494\n"}]}