send pack check for failure to send revisions list
When passing the revisions list to pack-objects we do not check for errors nor short writes. Introduce a new write_in_full which will handle short writes and report errors to the caller. Use this to short cut the send on failure, allowing us to wait for and report the child in case the failure is its fault. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Andy Whitcroft committed
Jan 2, 2007 at 14:12 UTC
825cee7b285d9c733e9aec03cf4362e8029ee1c1
3 files changed
+30
-2
cache.h
+1
@@ -420,6 +420,7 @@ extern char *git_commit_encoding;
420
extern char *git_log_output_encoding;
421
422
extern int copy_fd(int ifd, int ofd);
423
+extern int write_in_full(int fd, const void *buf, size_t count, const char *);
424
extern void write_or_die(int fd, const void *buf, size_t count);
425
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
426
send-pack.c
+6
-2
@@ -65,12 +65,16 @@ static int pack_objects(int fd, struct ref *refs)
65
memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
66
buf[0] = '^';
67
buf[41] = '\n';
68
- write(pipe_fd[1], buf, 42);
68
+ if (!write_in_full(pipe_fd[1], buf, 42,
69
+ "send-pack: send refs"))
70
+ break;
71
}
72
if (!is_null_sha1(refs->new_sha1)) {
73
memcpy(buf, sha1_to_hex(refs->new_sha1), 40);
74
buf[40] = '\n';
73
- write(pipe_fd[1], buf, 41);
75
+ if (!write_in_full(pipe_fd[1], buf, 41,
76
+ "send-pack: send refs"))
77
+ break;
78
}
79
refs = refs->next;
80
}
write_or_die.c
+23
@@ -43,3 +43,26 @@ int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
43
44
return 1;
45
}
46
+
47
+int write_in_full(int fd, const void *buf, size_t count, const char *msg)
48
+{
49
+ const char *p = buf;
50
+ ssize_t written;
51
+
52
+ while (count > 0) {
53
+ written = xwrite(fd, p, count);
54
+ if (written == 0) {
55
+ fprintf(stderr, "%s: disk full?\n", msg);
56
+ return 0;
57
+ }
58
+ else if (written < 0) {
59
+ fprintf(stderr, "%s: write error (%s)\n",
60
+ msg, strerror(errno));
61
+ return 0;
62
+ }
63
+ count -= written;
64
+ p += written;
65
+ }
66
+
67
+ return 1;
68
+}