Annotation of src/usr.bin/cvs/update.c, Revision 1.23
1.23 ! jfb 1: /* $OpenBSD: update.c,v 1.22 2005/04/16 20:31:18 xsa 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:
1.12 jfb 107: ret = 0;
108: rf = NULL;
109: root = CVS_DIR_ROOT(cf);
110: repo = CVS_DIR_REPO(cf);
1.14 jfb 111: fname = CVS_FILE_NAME(cf);
1.9 jfb 112:
1.13 jfb 113: if (cf->cf_type == DT_DIR) {
114: if (root->cr_method != CVS_METHOD_LOCAL) {
115: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
116: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
117: CVS_FILE_NAME(cf));
118: else
119: ret = cvs_senddir(root, cf);
120: }
121:
1.12 jfb 122: return (ret);
1.2 jfb 123: }
124:
1.12 jfb 125: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.2 jfb 126:
1.12 jfb 127: if (root->cr_method != CVS_METHOD_LOCAL) {
1.23 ! jfb 128: if (cvs_sendentry(root, cf) < 0) {
1.21 joris 129: return (CVS_EX_PROTO);
1.12 jfb 130: }
1.2 jfb 131:
132: switch (cf->cf_cvstat) {
1.12 jfb 133: case CVS_FST_UNKNOWN:
1.14 jfb 134: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, fname);
1.12 jfb 135: break;
1.2 jfb 136: case CVS_FST_UPTODATE:
1.14 jfb 137: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, fname);
1.2 jfb 138: break;
139: case CVS_FST_ADDED:
140: case CVS_FST_MODIFIED:
1.14 jfb 141: ret = cvs_sendreq(root, CVS_REQ_MODIFIED, fname);
1.12 jfb 142: if (ret == 0)
143: ret = cvs_sendfile(root, fpath);
1.2 jfb 144: break;
145: default:
1.12 jfb 146: break;
147: }
148: } else {
149: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
150: cvs_printf("? %s\n", fpath);
151: return (0);
152: }
153:
1.22 xsa 154: l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.16 jfb 155: root->cr_dir, repo, fname, RCS_FILE_EXT);
1.22 xsa 156: if (l == -1 || l >= (int)sizeof(rcspath)) {
157: errno = ENAMETOOLONG;
158: cvs_log(LP_ERRNO, "%s", rcspath);
159: return (-1);
160: }
1.12 jfb 161:
1.17 jfb 162: rf = rcs_open(rcspath, RCS_READ);
1.12 jfb 163: if (rf == NULL) {
1.21 joris 164: return (CVS_EX_DATA);
1.2 jfb 165: }
166:
1.12 jfb 167: rcs_close(rf);
1.2 jfb 168: }
169:
1.12 jfb 170: return (ret);
1.2 jfb 171: }
172:
173:
174: /*
175: * cvs_update_prune()
176: *
177: * Prune all directories which contain no more files known to CVS.
178: */
179: int
180: cvs_update_prune(CVSFILE *cf, void *arg)
181: {
1.1 jfb 182:
183: return (0);
184: }