Annotation of src/usr.bin/cvs/update.c, Revision 1.22
1.22 ! xsa 1: /* $OpenBSD: update.c,v 1.21 2005/04/12 14:58:40 joris Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.11 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.11 tedu 6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
1.1 jfb 9: *
1.11 tedu 10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
1.1 jfb 12: * 2. The name of the author may not be used to endorse or promote products
1.11 tedu 13: * derived from this software without specific prior written permission.
1.1 jfb 14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
1.11 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
27: #include <sys/param.h>
28: #include <sys/stat.h>
29:
30: #include <errno.h>
31: #include <stdio.h>
32: #include <fcntl.h>
33: #include <stdlib.h>
34: #include <unistd.h>
35: #include <string.h>
36:
37: #include "cvs.h"
38: #include "rcs.h"
39: #include "log.h"
1.4 jfb 40: #include "proto.h"
1.1 jfb 41:
42:
1.18 joris 43: int cvs_update_file(CVSFILE *, void *);
44: int cvs_update_prune(CVSFILE *, void *);
45: int cvs_update_options(char *, int, char **, int *);
46:
47: struct cvs_cmd_info cvs_update = {
48: cvs_update_options,
49: NULL,
50: cvs_update_file,
51: NULL, NULL,
52: CF_SORT | CF_RECURSE | CF_IGNORE | CF_KNOWN | CF_NOSYMS,
53: CVS_REQ_UPDATE,
54: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2 | CVS_CMD_SENDDIR
55: };
1.2 jfb 56:
1.1 jfb 57: int
1.18 joris 58: cvs_update_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 59: {
1.18 joris 60: int ch;
1.2 jfb 61:
1.18 joris 62: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 63: switch (ch) {
64: case 'A':
65: case 'C':
66: case 'D':
67: case 'd':
68: case 'f':
1.2 jfb 69: break;
1.1 jfb 70: case 'l':
1.18 joris 71: cvs_update.file_flags &= ~CF_RECURSE;
1.2 jfb 72: break;
1.1 jfb 73: case 'P':
74: case 'p':
75: case 'Q':
76: case 'q':
1.2 jfb 77: break;
1.1 jfb 78: case 'R':
1.18 joris 79: cvs_update.file_flags |= CF_RECURSE;
1.2 jfb 80: break;
1.1 jfb 81: case 'r':
82: break;
83: default:
1.21 joris 84: return (CVS_EX_USAGE);
1.1 jfb 85: }
86: }
87:
1.18 joris 88: *arg = optind;
1.2 jfb 89: return (0);
90: }
91:
92:
93: /*
94: * cvs_update_file()
95: *
1.12 jfb 96: * Update a single file. In the case where we act as client, send any
97: * pertinent information about that file to the server.
1.2 jfb 98: */
99: int
100: cvs_update_file(CVSFILE *cf, void *arg)
101: {
1.22 ! xsa 102: int ret, l;
1.14 jfb 103: char *fname, *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.2 jfb 104: RCSFILE *rf;
105: struct cvsroot *root;
106: struct cvs_ent *entp;
107:
1.12 jfb 108: ret = 0;
109: rf = NULL;
110: root = CVS_DIR_ROOT(cf);
111: repo = CVS_DIR_REPO(cf);
1.14 jfb 112: fname = CVS_FILE_NAME(cf);
1.9 jfb 113:
1.13 jfb 114: if (cf->cf_type == DT_DIR) {
115: if (root->cr_method != CVS_METHOD_LOCAL) {
116: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
117: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
118: CVS_FILE_NAME(cf));
119: else
120: ret = cvs_senddir(root, cf);
121: }
122:
1.12 jfb 123: return (ret);
1.2 jfb 124: }
125:
1.12 jfb 126: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.9 jfb 127: entp = cvs_ent_getent(fpath);
1.2 jfb 128:
1.12 jfb 129: if (root->cr_method != CVS_METHOD_LOCAL) {
130: if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
131: cvs_ent_free(entp);
1.21 joris 132: return (CVS_EX_PROTO);
1.12 jfb 133: }
1.2 jfb 134:
135: switch (cf->cf_cvstat) {
1.12 jfb 136: case CVS_FST_UNKNOWN:
1.14 jfb 137: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, fname);
1.12 jfb 138: break;
1.2 jfb 139: case CVS_FST_UPTODATE:
1.14 jfb 140: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, fname);
1.2 jfb 141: break;
142: case CVS_FST_ADDED:
143: case CVS_FST_MODIFIED:
1.14 jfb 144: ret = cvs_sendreq(root, CVS_REQ_MODIFIED, fname);
1.12 jfb 145: if (ret == 0)
146: ret = cvs_sendfile(root, fpath);
1.2 jfb 147: break;
148: default:
1.12 jfb 149: break;
150: }
151: } else {
152: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
153: cvs_printf("? %s\n", fpath);
154: return (0);
155: }
156:
1.22 ! xsa 157: l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.16 jfb 158: root->cr_dir, repo, fname, RCS_FILE_EXT);
1.22 ! xsa 159: if (l == -1 || l >= (int)sizeof(rcspath)) {
! 160: errno = ENAMETOOLONG;
! 161: cvs_log(LP_ERRNO, "%s", rcspath);
! 162:
! 163: cvs_ent_free(entp);
! 164: return (-1);
! 165: }
1.12 jfb 166:
1.17 jfb 167: rf = rcs_open(rcspath, RCS_READ);
1.12 jfb 168: if (rf == NULL) {
169: cvs_ent_free(entp);
1.21 joris 170: return (CVS_EX_DATA);
1.2 jfb 171: }
172:
1.12 jfb 173: rcs_close(rf);
1.2 jfb 174: }
175:
1.12 jfb 176: if (entp != NULL)
1.2 jfb 177: cvs_ent_free(entp);
1.12 jfb 178: return (ret);
1.2 jfb 179: }
180:
181:
182: /*
183: * cvs_update_prune()
184: *
185: * Prune all directories which contain no more files known to CVS.
186: */
187: int
188: cvs_update_prune(CVSFILE *cf, void *arg)
189: {
1.1 jfb 190:
191: return (0);
192: }