version 1.41, 2005/05/31 08:58:48 |
version 1.42, 2005/06/10 21:13:40 |
|
|
{ cvs_resp_m }, |
{ cvs_resp_m }, |
}; |
}; |
|
|
|
/* |
|
* Instead of opening and closing the Entry file all the time, |
|
* which caused a huge CPU load and slowed down everything, |
|
* we keep the Entry file for the directory we are working in |
|
* open until we encounter a new directory. |
|
*/ |
|
static char cvs_resp_lastdir[MAXPATHLEN] = ""; |
|
static CVSENTRIES *cvs_resp_lastent = NULL; |
|
static int resp_check_dir(const char *); |
|
|
|
|
/* |
/* |
* The MT command uses scoping to tag the data. Whenever we encouter a '+', |
* The MT command uses scoping to tag the data. Whenever we encouter a '+', |
* we push the name of the tag on the stack, and we pop it when we encounter |
* we push the name of the tag on the stack, and we pop it when we encounter |
|
|
static int |
static int |
cvs_resp_ok(struct cvsroot *root, int type, char *line) |
cvs_resp_ok(struct cvsroot *root, int type, char *line) |
{ |
{ |
|
/* |
|
* If we still have an Entry file open, close it now. |
|
*/ |
|
if (cvs_resp_lastent != NULL) |
|
cvs_ent_close(cvs_resp_lastent); |
|
|
return (1); |
return (1); |
} |
} |
|
|
{ |
{ |
char entbuf[128]; |
char entbuf[128]; |
struct cvs_ent *ent; |
struct cvs_ent *ent; |
CVSENTRIES *entfile; |
|
|
|
/* get the remote path */ |
/* get the remote path */ |
cvs_getln(root, entbuf, sizeof(entbuf)); |
cvs_getln(root, entbuf, sizeof(entbuf)); |
|
|
if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0) |
if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0) |
return (-1); |
return (-1); |
|
|
entfile = cvs_ent_open(line, O_WRONLY); |
if (resp_check_dir(line) < 0) |
if (entfile == NULL) |
|
return (-1); |
return (-1); |
|
|
if (type == CVS_RESP_NEWENTRY) { |
if (type == CVS_RESP_NEWENTRY) { |
cvs_ent_addln(entfile, entbuf); |
cvs_ent_addln(cvs_resp_lastent, entbuf); |
} else if (type == CVS_RESP_CHECKEDIN) { |
} else if (type == CVS_RESP_CHECKEDIN) { |
ent = cvs_ent_parse(entbuf); |
ent = cvs_ent_parse(entbuf); |
if (ent == NULL) { |
if (ent == NULL) { |
cvs_log(LP_ERR, "failed to parse entry"); |
cvs_log(LP_ERR, "failed to parse entry"); |
cvs_ent_close(entfile); |
|
return (-1); |
return (-1); |
} |
} |
|
|
|
|
ent->ce_mtime = time(&(ent->ce_mtime)); |
ent->ce_mtime = time(&(ent->ce_mtime)); |
|
|
/* replace the current entry with the one we just received */ |
/* replace the current entry with the one we just received */ |
(void)cvs_ent_remove(entfile, ent->ce_name); |
(void)cvs_ent_remove(cvs_resp_lastent, ent->ce_name); |
|
|
cvs_ent_add(entfile, ent); |
cvs_ent_add(cvs_resp_lastent, ent); |
} |
} |
cvs_ent_close(entfile); |
|
|
|
return (0); |
return (0); |
} |
} |
|
|
mode_t fmode; |
mode_t fmode; |
char path[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN]; |
char path[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN]; |
BUF *fbuf; |
BUF *fbuf; |
CVSENTRIES *entfile; |
|
struct cvs_ent *ep; |
struct cvs_ent *ep; |
struct timeval tv[2]; |
struct timeval tv[2]; |
|
|
|
|
} |
} |
ret = 0; |
ret = 0; |
|
|
entfile = cvs_ent_open(line, O_WRONLY); |
if (resp_check_dir(line) < 0) |
if (entfile == NULL) { |
|
cvs_ent_free(ep); |
|
return (-1); |
return (-1); |
} |
|
|
|
if (cvs_modtime != CVS_DATE_DMSEC) { |
if (cvs_modtime != CVS_DATE_DMSEC) { |
ep->ce_mtime = cvs_modtime; |
ep->ce_mtime = cvs_modtime; |
|
|
|
|
if ((type == CVS_RESP_UPDEXIST) || (type == CVS_RESP_UPDATED) || |
if ((type == CVS_RESP_UPDEXIST) || (type == CVS_RESP_UPDATED) || |
(type == CVS_RESP_MERGED) || (type == CVS_RESP_CREATED)) { |
(type == CVS_RESP_MERGED) || (type == CVS_RESP_CREATED)) { |
if ((cvs_ent_remove(entfile, ep->ce_name) < 0) && |
if ((cvs_ent_remove(cvs_resp_lastent, ep->ce_name) < 0) && |
(type != CVS_RESP_CREATED)) { |
(type != CVS_RESP_CREATED)) { |
cvs_log(LP_WARN, "failed to remove entry for '%s`", |
cvs_log(LP_WARN, "failed to remove entry for '%s`", |
ep->ce_name); |
ep->ce_name); |
} |
} |
} |
} |
|
|
if (cvs_ent_add(entfile, ep) < 0) { |
if (cvs_ent_add(cvs_resp_lastent, ep) < 0) { |
cvs_ent_free(ep); |
cvs_ent_free(ep); |
cvs_ent_close(entfile); |
|
return (-1); |
return (-1); |
} |
} |
|
|
cvs_ent_close(entfile); |
|
|
|
if ((fbuf = cvs_recvfile(root, &fmode)) == NULL) |
if ((fbuf = cvs_recvfile(root, &fmode)) == NULL) |
return (-1); |
return (-1); |
if (cvs_buf_write(fbuf, path, fmode) < 0) { |
if (cvs_buf_write(fbuf, path, fmode) < 0) { |
|
|
{ |
{ |
int l; |
int l; |
char buf[MAXPATHLEN], base[MAXPATHLEN], fpath[MAXPATHLEN], *file; |
char buf[MAXPATHLEN], base[MAXPATHLEN], fpath[MAXPATHLEN], *file; |
CVSENTRIES *ef; |
|
|
|
if (cvs_getln(root, buf, sizeof(buf)) < 0) |
if (cvs_getln(root, buf, sizeof(buf)) < 0) |
return (-1); |
return (-1); |
|
|
return (-1); |
return (-1); |
} |
} |
|
|
ef = cvs_ent_open(line, O_RDWR); |
if (resp_check_dir(line) < 0) |
if (ef == NULL) { |
return (-1); |
cvs_log(LP_ERR, "error handling `Removed' response"); |
|
if (type == CVS_RESP_RMENTRY) |
|
return (-1); |
|
} else { |
|
(void)cvs_ent_remove(ef, file); |
|
cvs_ent_close(ef); |
|
} |
|
|
|
|
(void)cvs_ent_remove(cvs_resp_lastent, file); |
if ((type == CVS_RESP_REMOVED) && ((unlink(fpath) == -1) && |
if ((type == CVS_RESP_REMOVED) && ((unlink(fpath) == -1) && |
errno != ENOENT)) { |
errno != ENOENT)) { |
cvs_log(LP_ERRNO, "failed to unlink `%s'", file); |
cvs_log(LP_ERRNO, "failed to unlink `%s'", file); |
|
|
tmpl = cvs_recvfile(root, &mode); |
tmpl = cvs_recvfile(root, &mode); |
if (tmpl == NULL) |
if (tmpl == NULL) |
return (-1); |
return (-1); |
|
|
|
return (0); |
|
} |
|
|
|
/* |
|
* Check if <dir> is the same as the last |
|
* received directory, if it's not, switch Entry files. |
|
*/ |
|
static int |
|
resp_check_dir(const char *dir) |
|
{ |
|
size_t len; |
|
|
|
if (strcmp(dir, cvs_resp_lastdir)) { |
|
if (cvs_resp_lastent != NULL) |
|
cvs_ent_close(cvs_resp_lastent); |
|
cvs_resp_lastent = cvs_ent_open(dir, O_WRONLY); |
|
if (cvs_resp_lastent == NULL) |
|
return (-1); |
|
|
|
len = strlcpy(cvs_resp_lastdir, dir, sizeof(cvs_resp_lastdir)); |
|
if (len >= sizeof(cvs_resp_lastdir)) { |
|
errno = ENAMETOOLONG; |
|
cvs_log(LP_ERRNO, "%s", cvs_resp_lastdir); |
|
return (-1); |
|
} |
|
} else { |
|
/* make sure the old one is still open */ |
|
if (cvs_resp_lastent == NULL) { |
|
cvs_resp_lastent = cvs_ent_open(cvs_resp_lastdir, |
|
O_WRONLY); |
|
if (cvs_resp_lastent == NULL) |
|
return (-1); |
|
} |
|
} |
|
|
return (0); |
return (0); |
} |
} |