diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2007-01-13 15:29:35 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2007-01-13 15:29:35 +0000 |
commit | c8b3d5534051a076fe062300cf465e1d046d7d73 (patch) | |
tree | 0290e4e18b6c54800fce4610708f423839f8c719 /usr.bin/cvs | |
parent | 123b36184f5ce3eeb87c053eb6a2ee377fb9e38f (diff) |
- remote update now works again, with new rcs api
- we no longer hold the entire file in memory when sending or receiving it
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/checkout.c | 35 | ||||
-rw-r--r-- | usr.bin/cvs/client.c | 10 | ||||
-rw-r--r-- | usr.bin/cvs/remote.c | 79 | ||||
-rw-r--r-- | usr.bin/cvs/remote.h | 4 | ||||
-rw-r--r-- | usr.bin/cvs/server.c | 9 |
5 files changed, 73 insertions, 64 deletions
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index 95877e3f1ec..60394f706e8 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.71 2007/01/12 23:56:11 joris Exp $ */ +/* $OpenBSD: checkout.c,v 1.72 2007/01/13 15:29:34 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -24,8 +24,10 @@ int cvs_checkout(int, char **); int cvs_export(int, char **); + static void checkout_check_repository(int, char **); static void checkout_repository(const char *, const char *); +static void checkout_write_revision(RCSFILE *, RCSNUM *, char *); extern int prune_dirs; extern int build_dirs; @@ -166,7 +168,8 @@ cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, BUF *bp, int flags) time_t rcstime; CVSENTRIES *ent; struct timeval tv[2]; - char *p, *entry, rev[16], timebuf[64], tbuf[32], stickytag[32]; + char *template, *p, *entry, rev[16], timebuf[64]; + char tbuf[32], stickytag[32]; rcsnum_tostr(rnum, rev, sizeof(rev)); @@ -264,16 +267,13 @@ cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, BUF *bp, int flags) cvs_remote_output(entry); if (!(flags & CO_COMMIT)) { -#if 0 - cvs_remote_output("u=rw,g=rw,o=rw"); - - /* XXX */ - printf("%ld\n", cvs_buf_len(nbp)); + (void)xasprintf(&template, + "%s/checkout.XXXXXXXXXX", cvs_tmpdir); - if (cvs_buf_write_fd(nbp, STDOUT_FILENO) == -1) - fatal("cvs_checkout_file: failed to send file"); - cvs_buf_free(nbp); -#endif + /* XXX - fd race below */ + checkout_write_revision(cf->file_rcs, rnum, template); + cvs_remote_send_file(template); + (void)unlink(template); } if (p != NULL) @@ -282,3 +282,16 @@ cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, BUF *bp, int flags) xfree(entry); } + +static void +checkout_write_revision(RCSFILE *rfp, RCSNUM *rev, char *template) +{ + int fd; + + if ((fd = mkstemp(template)) == -1) + fatal("mkstemp: '%s': %s", template, strerror(errno)); + + cvs_worklist_add(template, &temp_files); + rcs_rev_write_fd(rfp, rev, fd, 0); + (void)close(fd); +} diff --git a/usr.bin/cvs/client.c b/usr.bin/cvs/client.c index 8e19a27bf69..79da36dce85 100644 --- a/usr.bin/cvs/client.c +++ b/usr.bin/cvs/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.45 2007/01/11 02:35:55 joris Exp $ */ +/* $OpenBSD: client.c,v 1.46 2007/01/13 15:29:34 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -611,7 +611,6 @@ cvs_client_checkedin(char *data) void cvs_client_updated(char *data) { - BUF *bp; int l, fd; time_t now; mode_t fmode; @@ -670,16 +669,11 @@ cvs_client_updated(char *data) cvs_ent_close(ent, ENT_SYNC); xfree(entry); - bp = cvs_remote_receive_file(flen); if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1) fatal("cvs_client_updated: open: %s: %s", fpath, strerror(errno)); - if (cvs_buf_write_fd(bp, fd) == -1) - fatal("cvs_client_updated: cvs_buf_write_fd failed for %s", - fpath); - - cvs_buf_free(bp); + cvs_remote_receive_file(fd, flen); now = cvs_hack_time(now, 0); tv[0].tv_sec = now; diff --git a/usr.bin/cvs/remote.c b/usr.bin/cvs/remote.c index d8a1ba4374f..f5094ff96a8 100644 --- a/usr.bin/cvs/remote.c +++ b/usr.bin/cvs/remote.c @@ -1,4 +1,4 @@ -/* $OpenBSD: remote.c,v 1.5 2007/01/03 19:27:28 joris Exp $ */ +/* $OpenBSD: remote.c,v 1.6 2007/01/13 15:29:34 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -117,48 +117,50 @@ cvs_remote_input(void) return (ldata); } -BUF * -cvs_remote_receive_file(size_t len) +void +cvs_remote_receive_file(int fd, size_t len) { - BUF *bp; FILE *in; - size_t ret; char *data; + size_t nread, nwrite, nleft, toread; if (cvs_server_active) in = stdin; else in = current_cvsroot->cr_srvout; - bp = cvs_buf_alloc(len, BUF_AUTOEXT); + data = xmalloc(MAXBSIZE); + nleft = len; - if (len != 0) { - data = xmalloc(len); - ret = fread(data, sizeof(char), len, in); - if (ret != len) - fatal("length mismatch, expected %ld, got %ld", - len, ret); - cvs_buf_set(bp, data, len, 0); - xfree(data); - } + while (nleft > 0) { + toread = MIN(nleft, MAXBSIZE); - if (cvs_server_active == 0 && cvs_client_outlog_fd != -1) { - if (cvs_buf_write_fd(bp, cvs_client_outlog_fd) < 0) - fatal("cvs_remote_receive_file: cvs_buf_write_fd"); + nread = fread(data, sizeof(char), toread, in); + if (nread == 0) + fatal("error receiving file"); + + nwrite = write(fd, data, nread); + if (nwrite != nread) + fatal("failed to write %ld bytes", nread); + + if (cvs_server_active == 0 && + cvs_client_outlog_fd != -1) + (void)write(cvs_client_outlog_fd, data, nread); + + nleft -= nread; } - return (bp); + xfree(data); } void cvs_remote_send_file(const char *path) { - BUF *bp; int l, fd; - FILE *out; - size_t ret; + FILE *out, *in; + size_t ret, rw, total; struct stat st; - char buf[16], *fcont; + char buf[16], *data; if (cvs_server_active) out = stdout; @@ -179,24 +181,29 @@ cvs_remote_send_file(const char *path) fatal("cvs_remote_send_file: overflow"); cvs_remote_output(buf); - bp = cvs_buf_load_fd(fd, BUF_AUTOEXT); + if ((in = fdopen(fd, "r")) == NULL) + fatal("cvs_remote_send_file: fdopen %s", strerror(errno)); - if (cvs_server_active == 0 && cvs_client_inlog_fd != -1) { - if (cvs_buf_write_fd(bp, cvs_client_inlog_fd) < 0) - fatal("cvs_remote_send_file: cvs_buf_write"); - } + total = 0; + data = xmalloc(MAXBSIZE); + while ((ret = fread(data, sizeof(char), MAXBSIZE, in)) != 0) { + rw = fwrite(data, sizeof(char), ret, out); + if (rw != ret) + fatal("failed to write %ld bytes", ret); - fcont = cvs_buf_release(bp); + if (cvs_server_active == 0 && + cvs_client_outlog_fd != -1) + (void)write(cvs_client_outlog_fd, data, ret); - if (fcont != NULL) { - ret = fwrite(fcont, sizeof(char), st.st_size, out); - if (ret != st.st_size) - fatal("tried to write %lld only wrote %ld", - st.st_size, ret); - xfree(fcont); + total += ret; } - (void)close(fd); + xfree(data); + + if (total != st.st_size) + fatal("length mismatch, %ld vs %ld", total, st.st_size); + + (void)fclose(in); } void diff --git a/usr.bin/cvs/remote.h b/usr.bin/cvs/remote.h index 80df1555137..ea8dd061118 100644 --- a/usr.bin/cvs/remote.h +++ b/usr.bin/cvs/remote.h @@ -1,4 +1,4 @@ -/* $OpenBSD: remote.h,v 1.17 2007/01/03 22:28:30 joris Exp $ */ +/* $OpenBSD: remote.h,v 1.18 2007/01/13 15:29:34 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -102,7 +102,7 @@ void cvs_server_version(char *); void cvs_remote_classify_file(struct cvs_file *); void cvs_remote_output(const char *); char *cvs_remote_input(void); -BUF *cvs_remote_receive_file(size_t len); +void cvs_remote_receive_file(int, size_t); void cvs_remote_send_file(const char *); extern int cvs_client_inlog_fd; diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index 91c7aa05886..a8a8309cdd9 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.47 2007/01/03 22:28:30 joris Exp $ */ +/* $OpenBSD: server.c,v 1.48 2007/01/13 15:29:34 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -346,7 +346,6 @@ cvs_server_entry(char *data) void cvs_server_modified(char *data) { - BUF *bp; int fd; size_t flen; mode_t fmode; @@ -364,8 +363,6 @@ cvs_server_modified(char *data) fatal("cvs_server_modified: %s", errstr); xfree(len); - bp = cvs_remote_receive_file(flen); - fpath = xmalloc(MAXPATHLEN); if (cvs_path_cat(server_currentdir, data, fpath, MAXPATHLEN) >= MAXPATHLEN) @@ -374,15 +371,13 @@ cvs_server_modified(char *data) if ((fd = open(fpath, O_WRONLY | O_CREAT | O_TRUNC)) == -1) fatal("cvs_server_modified: %s: %s", fpath, strerror(errno)); - if (cvs_buf_write_fd(bp, fd) == -1) - fatal("cvs_server_modified: failed to write file '%s'", fpath); + cvs_remote_receive_file(fd, flen); if (fchmod(fd, 0600) == -1) fatal("cvs_server_modified: failed to set file mode"); xfree(fpath); (void)close(fd); - cvs_buf_free(bp); } void |