Annotation of src/usr.bin/cvs/update.c, Revision 1.18
1.18 ! joris 1: /* $OpenBSD: update.c,v 1.17 2005/02/27 00:22:08 jfb 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: #include <sysexits.h>
37:
38: #include "cvs.h"
39: #include "rcs.h"
40: #include "log.h"
1.4 jfb 41: #include "proto.h"
1.1 jfb 42:
43:
1.18 ! joris 44: int cvs_update_file(CVSFILE *, void *);
! 45: int cvs_update_prune(CVSFILE *, void *);
! 46: int cvs_update_options(char *, int, char **, int *);
! 47:
! 48: struct cvs_cmd_info cvs_update = {
! 49: cvs_update_options,
! 50: NULL,
! 51: cvs_update_file,
! 52: NULL, NULL,
! 53: CF_SORT | CF_RECURSE | CF_IGNORE | CF_KNOWN | CF_NOSYMS,
! 54: CVS_REQ_UPDATE,
! 55: CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2 | CVS_CMD_SENDDIR
! 56: };
1.2 jfb 57:
1.1 jfb 58: int
1.18 ! joris 59: cvs_update_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 60: {
1.18 ! joris 61: int ch;
1.2 jfb 62:
1.18 ! joris 63: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 64: switch (ch) {
65: case 'A':
66: case 'C':
67: case 'D':
68: case 'd':
69: case 'f':
1.2 jfb 70: break;
1.1 jfb 71: case 'l':
1.18 ! joris 72: cvs_update.file_flags &= ~CF_RECURSE;
1.2 jfb 73: break;
1.1 jfb 74: case 'P':
75: case 'p':
76: case 'Q':
77: case 'q':
1.2 jfb 78: break;
1.1 jfb 79: case 'R':
1.18 ! joris 80: cvs_update.file_flags |= CF_RECURSE;
1.2 jfb 81: break;
1.1 jfb 82: case 'r':
83: break;
84: default:
85: return (EX_USAGE);
86: }
87: }
88:
1.18 ! joris 89: *arg = optind;
1.2 jfb 90: return (0);
91: }
92:
93:
94: /*
95: * cvs_update_file()
96: *
1.12 jfb 97: * Update a single file. In the case where we act as client, send any
98: * pertinent information about that file to the server.
1.2 jfb 99: */
100: int
101: cvs_update_file(CVSFILE *cf, void *arg)
102: {
1.12 jfb 103: int ret;
1.14 jfb 104: char *fname, *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.2 jfb 105: RCSFILE *rf;
106: struct cvsroot *root;
107: struct cvs_ent *entp;
108:
1.12 jfb 109: ret = 0;
110: rf = NULL;
111: root = CVS_DIR_ROOT(cf);
112: repo = CVS_DIR_REPO(cf);
1.14 jfb 113: fname = CVS_FILE_NAME(cf);
1.9 jfb 114:
1.13 jfb 115: if (cf->cf_type == DT_DIR) {
116: if (root->cr_method != CVS_METHOD_LOCAL) {
117: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
118: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
119: CVS_FILE_NAME(cf));
120: else
121: ret = cvs_senddir(root, cf);
122: }
123:
1.12 jfb 124: return (ret);
1.2 jfb 125: }
126:
1.12 jfb 127: cvs_file_getpath(cf, fpath, sizeof(fpath));
1.9 jfb 128: entp = cvs_ent_getent(fpath);
1.2 jfb 129:
1.12 jfb 130: if (root->cr_method != CVS_METHOD_LOCAL) {
131: if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
132: cvs_ent_free(entp);
133: return (-1);
134: }
1.2 jfb 135:
136: switch (cf->cf_cvstat) {
1.12 jfb 137: case CVS_FST_UNKNOWN:
1.14 jfb 138: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, fname);
1.12 jfb 139: break;
1.2 jfb 140: case CVS_FST_UPTODATE:
1.14 jfb 141: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, fname);
1.2 jfb 142: break;
143: case CVS_FST_ADDED:
144: case CVS_FST_MODIFIED:
1.14 jfb 145: ret = cvs_sendreq(root, CVS_REQ_MODIFIED, fname);
1.12 jfb 146: if (ret == 0)
147: ret = cvs_sendfile(root, fpath);
1.2 jfb 148: break;
149: default:
1.12 jfb 150: break;
151: }
152: } else {
153: if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
154: cvs_printf("? %s\n", fpath);
155: return (0);
156: }
157:
158: snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.16 jfb 159: root->cr_dir, repo, fname, RCS_FILE_EXT);
1.12 jfb 160:
1.17 jfb 161: rf = rcs_open(rcspath, RCS_READ);
1.12 jfb 162: if (rf == NULL) {
163: cvs_ent_free(entp);
1.2 jfb 164: return (-1);
165: }
166:
1.12 jfb 167: rcs_close(rf);
1.2 jfb 168: }
169:
1.12 jfb 170: if (entp != NULL)
1.2 jfb 171: cvs_ent_free(entp);
1.12 jfb 172: return (ret);
1.2 jfb 173: }
174:
175:
176: /*
177: * cvs_update_prune()
178: *
179: * Prune all directories which contain no more files known to CVS.
180: */
181: int
182: cvs_update_prune(CVSFILE *cf, void *arg)
183: {
1.1 jfb 184:
185: return (0);
186: }