[BACK]Return to update.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/update.c, Revision 1.24

1.24    ! joris       1: /*     $OpenBSD: update.c,v 1.23 2005/04/18 21:02:50 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:
                     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 *);
1.24    ! joris      46: int cvs_update_sendflags(struct cvsroot *);
1.18      joris      47:
                     48: struct cvs_cmd_info cvs_update = {
                     49:        cvs_update_options,
1.24    ! joris      50:        cvs_update_sendflags,
1.18      joris      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.24    ! joris      58: static int Pflag, dflag, Aflag;
        !            59:
1.1       jfb        60: int
1.18      joris      61: cvs_update_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        62: {
1.18      joris      63:        int ch;
1.2       jfb        64:
1.24    ! joris      65:        Pflag = dflag = Aflag = 0;
        !            66:
1.18      joris      67:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        68:                switch (ch) {
                     69:                case 'A':
1.24    ! joris      70:                        Aflag = 1;
        !            71:                        break;
1.1       jfb        72:                case 'C':
                     73:                case 'D':
                     74:                case 'd':
1.24    ! joris      75:                        dflag = 1;
        !            76:                        break;
1.1       jfb        77:                case 'f':
1.2       jfb        78:                        break;
1.1       jfb        79:                case 'l':
1.18      joris      80:                        cvs_update.file_flags &= ~CF_RECURSE;
1.2       jfb        81:                        break;
1.1       jfb        82:                case 'P':
1.24    ! joris      83:                        Pflag = 1;
        !            84:                        break;
1.1       jfb        85:                case 'p':
                     86:                case 'Q':
                     87:                case 'q':
1.2       jfb        88:                        break;
1.1       jfb        89:                case 'R':
1.18      joris      90:                        cvs_update.file_flags |= CF_RECURSE;
1.2       jfb        91:                        break;
1.1       jfb        92:                case 'r':
                     93:                        break;
                     94:                default:
1.21      joris      95:                        return (CVS_EX_USAGE);
1.1       jfb        96:                }
                     97:        }
                     98:
1.18      joris      99:        *arg = optind;
1.2       jfb       100:        return (0);
                    101: }
                    102:
1.24    ! joris     103: int
        !           104: cvs_update_sendflags(struct cvsroot *root)
        !           105: {
        !           106:        if (Pflag && cvs_sendarg(root, "-P", 0) < 0)
        !           107:                return (CVS_EX_PROTO);
        !           108:        if (Aflag && cvs_sendarg(root, "-a", 0) < 0)
        !           109:                return (CVS_EX_PROTO);
        !           110:        if (dflag && cvs_sendarg(root, "-d", 0) < 0)
        !           111:                return (CVS_EX_PROTO);
        !           112:        return (0);
        !           113: }
1.2       jfb       114:
                    115: /*
                    116:  * cvs_update_file()
                    117:  *
1.12      jfb       118:  * Update a single file.  In the case where we act as client, send any
                    119:  * pertinent information about that file to the server.
1.2       jfb       120:  */
                    121: int
                    122: cvs_update_file(CVSFILE *cf, void *arg)
                    123: {
1.22      xsa       124:        int ret, l;
1.14      jfb       125:        char *fname, *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.2       jfb       126:        RCSFILE *rf;
                    127:        struct cvsroot *root;
                    128:
1.12      jfb       129:        ret = 0;
                    130:        rf = NULL;
                    131:        root = CVS_DIR_ROOT(cf);
                    132:        repo = CVS_DIR_REPO(cf);
1.14      jfb       133:        fname = CVS_FILE_NAME(cf);
1.9       jfb       134:
1.13      jfb       135:        if (cf->cf_type == DT_DIR) {
                    136:                if (root->cr_method != CVS_METHOD_LOCAL) {
                    137:                        if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    138:                                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    139:                                    CVS_FILE_NAME(cf));
                    140:                        else
                    141:                                ret = cvs_senddir(root, cf);
                    142:                }
                    143:
1.12      jfb       144:                return (ret);
1.2       jfb       145:        }
                    146:
1.12      jfb       147:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.2       jfb       148:
1.12      jfb       149:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.23      jfb       150:                if (cvs_sendentry(root, cf) < 0) {
1.21      joris     151:                        return (CVS_EX_PROTO);
1.12      jfb       152:                }
1.2       jfb       153:
                    154:                switch (cf->cf_cvstat) {
1.12      jfb       155:                case CVS_FST_UNKNOWN:
1.14      jfb       156:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, fname);
1.12      jfb       157:                        break;
1.2       jfb       158:                case CVS_FST_UPTODATE:
1.14      jfb       159:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, fname);
1.2       jfb       160:                        break;
                    161:                case CVS_FST_ADDED:
                    162:                case CVS_FST_MODIFIED:
1.14      jfb       163:                        ret = cvs_sendreq(root, CVS_REQ_MODIFIED, fname);
1.12      jfb       164:                        if (ret == 0)
                    165:                                ret = cvs_sendfile(root, fpath);
1.2       jfb       166:                        break;
                    167:                default:
1.12      jfb       168:                        break;
                    169:                }
                    170:        } else {
                    171:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    172:                        cvs_printf("? %s\n", fpath);
                    173:                        return (0);
                    174:                }
                    175:
1.22      xsa       176:                l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.16      jfb       177:                    root->cr_dir, repo, fname, RCS_FILE_EXT);
1.22      xsa       178:                if (l == -1 || l >= (int)sizeof(rcspath)) {
                    179:                        errno = ENAMETOOLONG;
                    180:                        cvs_log(LP_ERRNO, "%s", rcspath);
                    181:                        return (-1);
                    182:                }
1.12      jfb       183:
1.17      jfb       184:                rf = rcs_open(rcspath, RCS_READ);
1.12      jfb       185:                if (rf == NULL) {
1.21      joris     186:                        return (CVS_EX_DATA);
1.2       jfb       187:                }
                    188:
1.12      jfb       189:                rcs_close(rf);
1.2       jfb       190:        }
                    191:
1.12      jfb       192:        return (ret);
1.2       jfb       193: }
                    194:
                    195:
                    196: /*
                    197:  * cvs_update_prune()
                    198:  *
                    199:  * Prune all directories which contain no more files known to CVS.
                    200:  */
                    201: int
                    202: cvs_update_prune(CVSFILE *cf, void *arg)
                    203: {
1.1       jfb       204:
                    205:        return (0);
                    206: }