version 1.65, 2006/07/01 20:30:46 |
version 1.66, 2006/07/07 17:37:17 |
|
|
#include "cvs.h" |
#include "cvs.h" |
#include "log.h" |
#include "log.h" |
#include "diff.h" |
#include "diff.h" |
|
#include "remote.h" |
|
|
int cvs_checkout(int, char **); |
int cvs_checkout(int, char **); |
int cvs_export(int, char **); |
int cvs_export(int, char **); |
|
|
time_t rcstime; |
time_t rcstime; |
CVSENTRIES *ent; |
CVSENTRIES *ent; |
struct timeval tv[2]; |
struct timeval tv[2]; |
char *entry, rev[16], timebuf[64], tbuf[32], stickytag[32]; |
char *p, *entry, rev[16], timebuf[64], tbuf[32], stickytag[32]; |
|
|
rcsnum_tostr(rnum, rev, sizeof(rev)); |
rcsnum_tostr(rnum, rev, sizeof(rev)); |
|
|
cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d)", |
cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d) -> %s", |
cf->file_path, rev, flags); |
cf->file_path, rev, flags, |
|
(cvs_server_active) ? "to client" : "to disk"); |
|
|
nbp = rcs_kwexp_buf(bp, cf->file_rcs, rnum); |
nbp = rcs_kwexp_buf(bp, cf->file_rcs, rnum); |
|
|
if (flags & CO_DUMP) { |
if (flags & CO_DUMP) { |
if (cvs_buf_write_fd(nbp, STDOUT_FILENO) == -1) |
if (cvs_server_active) { |
fatal("cvs_checkout_file: %s", strerror(errno)); |
cvs_printf("dump file %s to client\n", cf->file_path); |
|
} else { |
|
if (cvs_buf_write_fd(nbp, STDOUT_FILENO) == -1) |
|
fatal("cvs_checkout_file: %s", strerror(errno)); |
|
} |
|
|
cvs_buf_free(nbp); |
cvs_buf_free(nbp); |
return; |
return; |
} |
} |
|
|
oflags = O_WRONLY | O_TRUNC; |
if (cvs_server_active == 0) { |
if (cf->fd != -1) { |
oflags = O_WRONLY | O_TRUNC; |
exists = 1; |
if (cf->fd != -1) { |
(void)close(cf->fd); |
exists = 1; |
} else { |
(void)close(cf->fd); |
exists = 0; |
} else { |
oflags |= O_CREAT; |
exists = 0; |
} |
oflags |= O_CREAT; |
|
} |
|
|
cf->fd = open(cf->file_path, oflags); |
cf->fd = open(cf->file_path, oflags); |
if (cf->fd == -1) |
if (cf->fd == -1) |
fatal("cvs_checkout_file: open: %s", strerror(errno)); |
fatal("cvs_checkout_file: open: %s", strerror(errno)); |
|
|
if (cvs_buf_write_fd(nbp, cf->fd) == -1) |
if (cvs_buf_write_fd(nbp, cf->fd) == -1) |
fatal("cvs_checkout_file: %s", strerror(errno)); |
fatal("cvs_checkout_file: %s", strerror(errno)); |
|
|
cvs_buf_free(nbp); |
cvs_buf_free(nbp); |
|
|
if (fchmod(cf->fd, 0644) == -1) |
if (fchmod(cf->fd, 0644) == -1) |
fatal("cvs_checkout_file: fchmod: %s", strerror(errno)); |
fatal("cvs_checkout_file: fchmod: %s", strerror(errno)); |
|
|
if (exists == 0) { |
if (exists == 0) { |
rcstime = rcs_rev_getdate(cf->file_rcs, rnum); |
rcstime = rcs_rev_getdate(cf->file_rcs, rnum); |
rcstime = cvs_hack_time(rcstime, 0); |
rcstime = cvs_hack_time(rcstime, 0); |
|
} else { |
|
time(&rcstime); |
|
} |
|
|
|
tv[0].tv_sec = rcstime; |
|
tv[0].tv_usec = 0; |
|
tv[1] = tv[0]; |
|
if (futimes(cf->fd, tv) == -1) |
|
fatal("cvs_checkout_file: futimes: %s", |
|
strerror(errno)); |
} else { |
} else { |
time(&rcstime); |
time(&rcstime); |
} |
} |
|
|
tv[0].tv_sec = rcstime; |
|
tv[0].tv_usec = 0; |
|
tv[1] = tv[0]; |
|
if (futimes(cf->fd, tv) == -1) |
|
fatal("cvs_checkout_file: futimes: %s", strerror(errno)); |
|
|
|
rcstime = cvs_hack_time(rcstime, 1); |
rcstime = cvs_hack_time(rcstime, 1); |
|
|
ctime_r(&rcstime, tbuf); |
ctime_r(&rcstime, tbuf); |
|
|
l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//%s", cf->file_name, |
l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//%s", cf->file_name, |
rev, timebuf, stickytag); |
rev, timebuf, stickytag); |
|
|
ent = cvs_ent_open(cf->file_wd); |
if (cvs_server_active == 0) { |
cvs_ent_add(ent, entry); |
ent = cvs_ent_open(cf->file_wd); |
cvs_ent_close(ent, ENT_SYNC); |
cvs_ent_add(ent, entry); |
|
cvs_ent_close(ent, ENT_SYNC); |
|
} else { |
|
if ((p = strrchr(cf->file_rpath, ',')) != NULL) |
|
*p = '\0'; |
|
|
|
cvs_server_send_response("Updated %s/", cf->file_wd); |
|
cvs_remote_output(cf->file_rpath); |
|
cvs_remote_output(entry); |
|
cvs_remote_output("u=rw,g=rw,o=rw"); |
|
|
|
/* XXX */ |
|
printf("%ld\n", cvs_buf_len(nbp)); |
|
|
|
if (cvs_buf_write_fd(nbp, STDOUT_FILENO) == -1) |
|
fatal("cvs_checkout_file: failed to send file"); |
|
cvs_buf_free(nbp); |
|
|
|
if (p != NULL) |
|
*p = ','; |
|
} |
|
|
xfree(entry); |
xfree(entry); |
} |
} |