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

1.16    ! jfb         1: /*     $OpenBSD: update.c,v 1.15 2005/02/04 17:50:20 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.2       jfb        44: int  cvs_update_file  (CVSFILE *, void *);
                     45: int  cvs_update_prune (CVSFILE *, void *);
                     46:
                     47:
1.1       jfb        48: /*
                     49:  * cvs_update()
                     50:  *
                     51:  * Handle the `cvs update' command.
1.2       jfb        52:  * Returns 0 on success, or the appropriate exit code on error.
1.1       jfb        53:  */
                     54: int
                     55: cvs_update(int argc, char **argv)
                     56: {
1.12      jfb        57:        int i, ch, flags;
                     58:        struct cvsroot *root;
1.2       jfb        59:
1.8       jfb        60:        flags = CF_SORT|CF_RECURSE|CF_IGNORE|CF_KNOWN|CF_NOSYMS;
1.1       jfb        61:
                     62:        while ((ch = getopt(argc, argv, "ACD:dflPpQqRr:")) != -1) {
                     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.2       jfb        71:                        flags &= ~CF_RECURSE;
                     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.2       jfb        79:                        flags |= CF_RECURSE;
                     80:                        break;
1.1       jfb        81:                case 'r':
                     82:                        break;
                     83:                default:
                     84:                        return (EX_USAGE);
                     85:                }
                     86:        }
                     87:
                     88:        argc -= optind;
                     89:        argv += optind;
1.2       jfb        90:
1.12      jfb        91:        if (argc == 0)
1.7       jfb        92:                cvs_files = cvs_file_get(".", flags);
1.12      jfb        93:        else {
1.2       jfb        94:                /* don't perform ignore on explicitly listed files */
1.7       jfb        95:                flags &= ~(CF_IGNORE | CF_RECURSE | CF_SORT);
                     96:                cvs_files = cvs_file_getspec(argv, argc, flags);
1.2       jfb        97:        }
1.7       jfb        98:        if (cvs_files == NULL)
                     99:                return (EX_DATAERR);
1.2       jfb       100:
1.12      jfb       101:        root = CVS_DIR_ROOT(cvs_files);
                    102:        if (root == NULL) {
                    103:                cvs_log(LP_ERR,
                    104:                    "No CVSROOT specified!  Please use the `-d' option");
                    105:                cvs_log(LP_ERR,
                    106:                    "or set the CVSROOT environment variable.");
                    107:                return (EX_USAGE);
                    108:        }
                    109:        if ((root->cr_method != CVS_METHOD_LOCAL) && (cvs_connect(root) < 0))
                    110:                return (EX_PROTOCOL);
                    111:
1.7       jfb       112:        cvs_file_examine(cvs_files, cvs_update_file, NULL);
1.2       jfb       113:
1.12      jfb       114:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    115:                if (cvs_senddir(root, cvs_files) < 0)
                    116:                        return (EX_PROTOCOL);
                    117:
                    118:                for (i = 0; i < argc; i++)
                    119:                        if (cvs_sendarg(root, argv[i], 0) < 0)
                    120:                                return (EX_PROTOCOL);
                    121:                if (cvs_sendreq(root, CVS_REQ_UPDATE, NULL) < 0)
                    122:                        return (EX_PROTOCOL);
                    123:        }
1.2       jfb       124:
                    125:        return (0);
                    126: }
                    127:
                    128:
                    129: /*
                    130:  * cvs_update_file()
                    131:  *
1.12      jfb       132:  * Update a single file.  In the case where we act as client, send any
                    133:  * pertinent information about that file to the server.
1.2       jfb       134:  */
                    135: int
                    136: cvs_update_file(CVSFILE *cf, void *arg)
                    137: {
1.12      jfb       138:        int ret;
1.14      jfb       139:        char *fname, *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.2       jfb       140:        RCSFILE *rf;
                    141:        struct cvsroot *root;
                    142:        struct cvs_ent *entp;
                    143:
1.12      jfb       144:        ret = 0;
                    145:        rf = NULL;
                    146:        root = CVS_DIR_ROOT(cf);
                    147:        repo = CVS_DIR_REPO(cf);
1.14      jfb       148:        fname = CVS_FILE_NAME(cf);
1.9       jfb       149:
1.13      jfb       150:        if (cf->cf_type == DT_DIR) {
                    151:                if (root->cr_method != CVS_METHOD_LOCAL) {
                    152:                        if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    153:                                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    154:                                    CVS_FILE_NAME(cf));
                    155:                        else
                    156:                                ret = cvs_senddir(root, cf);
                    157:                }
                    158:
1.12      jfb       159:                return (ret);
1.2       jfb       160:        }
                    161:
1.12      jfb       162:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.9       jfb       163:        entp = cvs_ent_getent(fpath);
1.2       jfb       164:
1.12      jfb       165:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    166:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
                    167:                        cvs_ent_free(entp);
                    168:                        return (-1);
                    169:                }
1.2       jfb       170:
                    171:                switch (cf->cf_cvstat) {
1.12      jfb       172:                case CVS_FST_UNKNOWN:
1.14      jfb       173:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, fname);
1.12      jfb       174:                        break;
1.2       jfb       175:                case CVS_FST_UPTODATE:
1.14      jfb       176:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, fname);
1.2       jfb       177:                        break;
                    178:                case CVS_FST_ADDED:
                    179:                case CVS_FST_MODIFIED:
1.14      jfb       180:                        ret = cvs_sendreq(root, CVS_REQ_MODIFIED, fname);
1.12      jfb       181:                        if (ret == 0)
                    182:                                ret = cvs_sendfile(root, fpath);
1.2       jfb       183:                        break;
                    184:                default:
1.12      jfb       185:                        break;
                    186:                }
                    187:        } else {
                    188:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    189:                        cvs_printf("? %s\n", fpath);
                    190:                        return (0);
                    191:                }
                    192:
                    193:                snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.16    ! jfb       194:                    root->cr_dir, repo, fname, RCS_FILE_EXT);
1.12      jfb       195:
                    196:                rf = rcs_open(rcspath, RCS_MODE_READ);
                    197:                if (rf == NULL) {
                    198:                        cvs_ent_free(entp);
1.2       jfb       199:                        return (-1);
                    200:                }
                    201:
1.12      jfb       202:                rcs_close(rf);
1.2       jfb       203:        }
                    204:
1.12      jfb       205:        if (entp != NULL)
1.2       jfb       206:                cvs_ent_free(entp);
1.12      jfb       207:        return (ret);
1.2       jfb       208: }
                    209:
                    210:
                    211: /*
                    212:  * cvs_update_prune()
                    213:  *
                    214:  * Prune all directories which contain no more files known to CVS.
                    215:  */
                    216: int
                    217: cvs_update_prune(CVSFILE *cf, void *arg)
                    218: {
1.1       jfb       219:
                    220:        return (0);
                    221: }