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

1.12    ! jfb         1: /*     $OpenBSD: update.c,v 1.11 2004/12/07 17:10:56 tedu 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.9       jfb       139:        char *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.9       jfb       148:
1.12    ! jfb       149:        if ((root->cr_method != CVS_METHOD_LOCAL) && (cf->cf_type == DT_DIR)) {
        !           150:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
        !           151:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
1.9       jfb       152:                            CVS_FILE_NAME(cf));
1.2       jfb       153:                else
1.12    ! jfb       154:                        ret = cvs_senddir(root, cf);
        !           155:                return (ret);
1.2       jfb       156:        }
                    157:
1.12    ! jfb       158:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.9       jfb       159:        entp = cvs_ent_getent(fpath);
1.2       jfb       160:
1.12    ! jfb       161:        if (root->cr_method != CVS_METHOD_LOCAL) {
        !           162:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
        !           163:                        cvs_ent_free(entp);
        !           164:                        return (-1);
        !           165:                }
1.2       jfb       166:
                    167:                switch (cf->cf_cvstat) {
1.12    ! jfb       168:                case CVS_FST_UNKNOWN:
        !           169:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
        !           170:                            CVS_FILE_NAME(cf));
        !           171:                        break;
1.2       jfb       172:                case CVS_FST_UPTODATE:
1.12    ! jfb       173:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
        !           174:                            CVS_FILE_NAME(cf));
1.2       jfb       175:                        break;
                    176:                case CVS_FST_ADDED:
                    177:                case CVS_FST_MODIFIED:
1.12    ! jfb       178:                        ret = cvs_sendreq(root, CVS_REQ_MODIFIED,
        !           179:                            CVS_FILE_NAME(cf));
        !           180:                        if (ret == 0)
        !           181:                                ret = cvs_sendfile(root, fpath);
1.2       jfb       182:                        break;
                    183:                default:
1.12    ! jfb       184:                        break;
        !           185:                }
        !           186:        } else {
        !           187:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
        !           188:                        cvs_printf("? %s\n", fpath);
        !           189:                        return (0);
        !           190:                }
        !           191:
        !           192:                snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
        !           193:                    root->cr_dir, repo, fpath, RCS_FILE_EXT);
        !           194:
        !           195:                rf = rcs_open(rcspath, RCS_MODE_READ);
        !           196:                if (rf == NULL) {
        !           197:                        cvs_ent_free(entp);
1.2       jfb       198:                        return (-1);
                    199:                }
                    200:
1.12    ! jfb       201:                rcs_close(rf);
1.2       jfb       202:        }
                    203:
1.12    ! jfb       204:        if (entp != NULL)
1.2       jfb       205:                cvs_ent_free(entp);
1.12    ! jfb       206:        return (ret);
1.2       jfb       207: }
                    208:
                    209:
                    210: /*
                    211:  * cvs_update_prune()
                    212:  *
                    213:  * Prune all directories which contain no more files known to CVS.
                    214:  */
                    215: int
                    216: cvs_update_prune(CVSFILE *cf, void *arg)
                    217: {
1.1       jfb       218:
                    219:        return (0);
                    220: }