1 /* $OpenBSD: add.c,v 1.4 2004/08/13 13:27:52 jfb Exp $ */ 2 /* 3 * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 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 24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include <sys/types.h> 28 29 #include <errno.h> 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <unistd.h> 33 #include <string.h> 34 #include <sysexits.h> 35 36 #include "cvs.h" 37 #include "log.h" 38 #include "proto.h" 39 40 41 extern char *__progname; 42 43 44 45 int cvs_add_file (CVSFILE *, void *); 46 47 48 49 /* 50 * cvs_add() 51 * 52 * Handler for the `cvs add' command. 53 * Returns 0 on success, or one of the known system exit codes on failure. 54 */ 55 56 int 57 cvs_add(int argc, char **argv) 58 { 59 int i, ch; 60 char *kflag, *msg; 61 struct cvsroot *root; 62 63 kflag = NULL; 64 65 while ((ch = getopt(argc, argv, "k:m:")) != -1) { 66 switch (ch) { 67 case 'k': 68 kflag = optarg; 69 break; 70 case 'm': 71 msg = optarg; 72 break; 73 default: 74 return (EX_USAGE); 75 } 76 } 77 78 argc -= optind; 79 argv += optind; 80 81 if (argc == 0) 82 return (EX_USAGE); 83 84 cvs_files = cvs_file_getspec(argv, argc, 0); 85 if (cvs_files == NULL) 86 return (EX_DATAERR); 87 88 cvs_file_examine(cvs_files, cvs_add_file, NULL); 89 90 root = CVS_DIR_ROOT(cvs_files); 91 92 for (i = 0; i < argc; i++) 93 cvs_sendarg(root, argv[i], 0); 94 if (cvs_sendreq(root, CVS_REQ_ADD, NULL) < 0) 95 return (-1); 96 97 return (0); 98 } 99 100 101 int 102 cvs_add_file(CVSFILE *cf, void *arg) 103 { 104 struct cvsroot *root; 105 106 if (cf->cf_type == DT_DIR) { 107 if (cf->cf_cvstat == CVS_FST_UNKNOWN) { 108 } 109 else { 110 root = cf->cf_ddat->cd_root; 111 if ((cf->cf_parent == NULL) || 112 (root != cf->cf_parent->cf_ddat->cd_root)) { 113 cvs_connect(root); 114 } 115 116 cvs_senddir(root, cf); 117 } 118 119 return (0); 120 } 121 122 root = CVS_DIR_ROOT(cf); 123 124 cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name); 125 126 if (cvs_cmdop == CVS_OP_SERVER) { 127 cvs_log(LP_INFO, "scheduling file `%s' for addition", 128 cf->cf_name); 129 cvs_log(LP_INFO, "use `%s commit' to add this file permanently", 130 __progname); 131 } 132 133 return (0); 134 } 135