[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.29

1.29    ! jfb         1: /*     $OpenBSD: update.c,v 1.28 2005/05/20 20:00:53 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.29    ! jfb        43: static int cvs_update_init     (struct cvs_cmd *, int, char **, int *);
        !            44: static int cvs_update_pre_exec (struct cvsroot *);
1.26      jfb        45: static int cvs_update_remote    (CVSFILE *, void *);
                     46: static int cvs_update_local     (CVSFILE *, void *);
1.18      joris      47:
1.29    ! jfb        48:
        !            49: struct cvs_cmd cvs_cmd_update = {
        !            50:        CVS_OP_UPDATE, CVS_REQ_UPDATE, "update",
        !            51:        { "up", "upd" },
        !            52:        "Bring work tree in sync with repository",
        !            53:        "[-ACdflPpR] [-D date | -r rev] [-I ign] [-j rev] [-k mode] "
        !            54:        "[-t id] ...",
        !            55:        "ACD:dflPpQqRr:",
        !            56:        NULL,
        !            57:        CF_SORT | CF_RECURSE | CF_IGNORE | CF_KNOWN | CF_NOSYMS,
        !            58:        cvs_update_init,
        !            59:        cvs_update_pre_exec,
1.26      jfb        60:        cvs_update_remote,
1.29    ! jfb        61:        cvs_update_local,
        !            62:        NULL,
        !            63:        NULL,
1.18      joris      64:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2 | CVS_CMD_SENDDIR
                     65: };
1.2       jfb        66:
1.24      joris      67: static int Pflag, dflag, Aflag;
                     68:
1.26      jfb        69: static int
1.29    ! jfb        70: cvs_update_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1       jfb        71: {
1.18      joris      72:        int ch;
1.2       jfb        73:
1.24      joris      74:        Pflag = dflag = Aflag = 0;
                     75:
1.29    ! jfb        76:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1       jfb        77:                switch (ch) {
                     78:                case 'A':
1.24      joris      79:                        Aflag = 1;
                     80:                        break;
1.1       jfb        81:                case 'C':
                     82:                case 'D':
                     83:                case 'd':
1.24      joris      84:                        dflag = 1;
                     85:                        break;
1.1       jfb        86:                case 'f':
1.2       jfb        87:                        break;
1.1       jfb        88:                case 'l':
1.29    ! jfb        89:                        cmd->file_flags &= ~CF_RECURSE;
1.2       jfb        90:                        break;
1.1       jfb        91:                case 'P':
1.24      joris      92:                        Pflag = 1;
                     93:                        break;
1.1       jfb        94:                case 'p':
1.27      xsa        95:                        cvs_noexec = 1; /* no locks will be created */
                     96:                        break;
1.1       jfb        97:                case 'Q':
                     98:                case 'q':
1.2       jfb        99:                        break;
1.1       jfb       100:                case 'R':
1.29    ! jfb       101:                        cmd->file_flags |= CF_RECURSE;
1.2       jfb       102:                        break;
1.1       jfb       103:                case 'r':
                    104:                        break;
                    105:                default:
1.21      joris     106:                        return (CVS_EX_USAGE);
1.1       jfb       107:                }
                    108:        }
                    109:
1.18      joris     110:        *arg = optind;
1.2       jfb       111:        return (0);
                    112: }
                    113:
1.26      jfb       114: static int
1.29    ! jfb       115: cvs_update_pre_exec(struct cvsroot *root)
1.24      joris     116: {
                    117:        if (Pflag && cvs_sendarg(root, "-P", 0) < 0)
                    118:                return (CVS_EX_PROTO);
1.25      joris     119:        if (Aflag && cvs_sendarg(root, "-A", 0) < 0)
1.24      joris     120:                return (CVS_EX_PROTO);
                    121:        if (dflag && cvs_sendarg(root, "-d", 0) < 0)
                    122:                return (CVS_EX_PROTO);
                    123:        return (0);
                    124: }
1.2       jfb       125:
                    126: /*
1.26      jfb       127:  * cvs_update_remote()
1.2       jfb       128:  *
1.12      jfb       129:  * Update a single file.  In the case where we act as client, send any
                    130:  * pertinent information about that file to the server.
1.2       jfb       131:  */
1.26      jfb       132: static int
                    133: cvs_update_remote(CVSFILE *cf, void *arg)
1.2       jfb       134: {
1.26      jfb       135:        int ret;
                    136:        char *repo, fpath[MAXPATHLEN];
1.2       jfb       137:        struct cvsroot *root;
                    138:
1.12      jfb       139:        ret = 0;
                    140:        root = CVS_DIR_ROOT(cf);
                    141:        repo = CVS_DIR_REPO(cf);
1.9       jfb       142:
1.13      jfb       143:        if (cf->cf_type == DT_DIR) {
1.26      jfb       144:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    145:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    146:                            cf->cf_name);
                    147:                else
                    148:                        ret = cvs_senddir(root, cf);
1.13      jfb       149:
1.28      joris     150:                if (ret == -1)
                    151:                        ret = CVS_EX_PROTO;
                    152:
1.12      jfb       153:                return (ret);
1.2       jfb       154:        }
                    155:
1.12      jfb       156:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.2       jfb       157:
1.26      jfb       158:        if (cvs_sendentry(root, cf) < 0)
                    159:                return (CVS_EX_PROTO);
1.2       jfb       160:
1.26      jfb       161:        switch (cf->cf_cvstat) {
                    162:        case CVS_FST_UNKNOWN:
                    163:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
                    164:                break;
                    165:        case CVS_FST_UPTODATE:
                    166:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
                    167:                break;
                    168:        case CVS_FST_ADDED:
                    169:        case CVS_FST_MODIFIED:
                    170:                ret = cvs_sendreq(root, CVS_REQ_MODIFIED, cf->cf_name);
                    171:                if (ret == 0)
                    172:                        ret = cvs_sendfile(root, fpath);
                    173:                break;
                    174:        default:
                    175:                break;
1.2       jfb       176:        }
                    177:
1.28      joris     178:        if (ret == -1)
                    179:                ret = CVS_EX_PROTO;
                    180:
1.12      jfb       181:        return (ret);
1.2       jfb       182: }
                    183:
                    184: /*
1.26      jfb       185:  * cvs_update_local()
1.2       jfb       186:  */
1.26      jfb       187: static int
                    188: cvs_update_local(CVSFILE *cf, void *arg)
1.2       jfb       189: {
1.26      jfb       190:        int ret, l;
                    191:        char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
                    192:        RCSFILE *rf;
                    193:        struct cvsroot *root;
                    194:
1.29    ! jfb       195:        printf("cvs_update_local(%s)\n", cf->cf_name);
1.26      jfb       196:        ret = 0;
                    197:        rf = NULL;
                    198:        root = CVS_DIR_ROOT(cf);
                    199:        repo = CVS_DIR_REPO(cf);
                    200:
1.29    ! jfb       201:        cvs_file_getpath(cf, fpath, sizeof(fpath));
        !           202:
1.26      jfb       203:        if (cf->cf_type == DT_DIR) {
1.29    ! jfb       204:                cvs_log(LP_INFO, "Updating %s", fpath);
1.26      jfb       205:                return (CVS_EX_OK);
                    206:        }
                    207:
                    208:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    209:                cvs_printf("? %s\n", fpath);
                    210:                return (0);
                    211:        }
                    212:
                    213:        l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
                    214:            root->cr_dir, repo, cf->cf_name, RCS_FILE_EXT);
                    215:        if (l == -1 || l >= (int)sizeof(rcspath)) {
                    216:                errno = ENAMETOOLONG;
                    217:                cvs_log(LP_ERRNO, "%s", rcspath);
1.28      joris     218:                return (CVS_EX_DATA);
1.26      jfb       219:        }
1.1       jfb       220:
1.29    ! jfb       221:        printf("opening %s\n", rcspath);
1.26      jfb       222:        rf = rcs_open(rcspath, RCS_RDWR);
                    223:        if (rf == NULL) {
1.29    ! jfb       224:                printf("failed here?\n");
1.26      jfb       225:                return (CVS_EX_DATA);
                    226:        }
                    227:
                    228:        rcs_close(rf);
                    229:
                    230:        return (ret);
1.1       jfb       231: }