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

Annotation of src/usr.bin/cvs/remove.c, Revision 1.58

1.58    ! joris       1: /*     $OpenBSD: remove.c,v 1.57 2006/12/14 09:31:17 xsa Exp $ */
1.1       xsa         2: /*
1.46      joris       3:  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       xsa         4:  *
1.46      joris       5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
1.1       xsa         8:  *
1.46      joris       9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       xsa        16:  */
                     17:
1.40      xsa        18: #include "includes.h"
1.1       xsa        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
1.55      xsa        22: #include "remote.h"
1.1       xsa        23:
                     24: extern char *__progname;
                     25:
1.46      joris      26: void           cvs_remove_local(struct cvs_file *);
1.1       xsa        27:
1.46      joris      28: static int     force_remove = 0;
                     29: static int     removed = 0;
                     30: static int     existing = 0;
1.4       joris      31:
1.16      jfb        32: struct cvs_cmd cvs_cmd_remove = {
1.53      joris      33:        CVS_OP_REMOVE, 0, "remove",
1.16      jfb        34:        { "rm", "delete" },
                     35:        "Remove an entry from the repository",
                     36:        "[-flR] [file ...]",
                     37:        "flR",
1.4       joris      38:        NULL,
1.46      joris      39:        cvs_remove
1.4       joris      40: };
1.1       xsa        41:
1.46      joris      42: int
                     43: cvs_remove(int argc, char **argv)
1.1       xsa        44: {
1.4       joris      45:        int ch;
1.47      joris      46:        int flags;
1.46      joris      47:        char *arg = ".";
                     48:        struct cvs_recursion cr;
1.1       xsa        49:
1.47      joris      50:        flags = CR_RECURSE_DIRS;
1.48      xsa        51:        while ((ch = getopt(argc, argv, cvs_cmd_remove.cmd_opts)) != -1) {
1.1       xsa        52:                switch (ch) {
                     53:                case 'f':
1.3       xsa        54:                        force_remove = 1;
1.1       xsa        55:                        break;
                     56:                case 'l':
1.47      joris      57:                        flags &= ~CR_RECURSE_DIRS;
1.1       xsa        58:                        break;
                     59:                case 'R':
                     60:                        break;
                     61:                default:
1.48      xsa        62:                        fatal("%s", cvs_cmd_remove.cmd_synopsis);
1.1       xsa        63:                }
                     64:        }
                     65:
                     66:        argc -= optind;
                     67:        argv += optind;
                     68:
1.46      joris      69:        cr.enterdir = NULL;
                     70:        cr.leavedir = NULL;
1.55      xsa        71:
                     72:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                     73:                cr.fileproc = cvs_client_sendfile;
                     74:
                     75:                if (!(flags & CR_RECURSE_DIRS))
                     76:                        cvs_client_send_request("Argument -l");
                     77:        } else {
                     78:                cr.fileproc = cvs_remove_local;
                     79:        }
                     80:
1.47      joris      81:        cr.flags = flags;
1.46      joris      82:
                     83:        if (argc > 0)
                     84:                cvs_file_run(argc, argv, &cr);
                     85:        else
                     86:                cvs_file_run(1, &arg, &cr);
1.11      xsa        87:
1.55      xsa        88:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                     89:                cvs_client_send_files(argv, argc);
                     90:                cvs_client_senddir(".");
                     91:                cvs_client_send_request("remove");
                     92:                cvs_client_get_responses();
                     93:        } else {
                     94:                if (existing != 0) {
1.56      xsa        95:                        cvs_log(LP_ERR, (existing == 1) ?
                     96:                            "%d file exists; remove it first" :
                     97:                            "%d files exist; remove them first", existing);
1.55      xsa        98:                }
1.49      joris      99:
1.55      xsa       100:                if (removed != 0) {
1.58    ! joris     101:                        if (verbosity > 0) {
1.55      xsa       102:                                cvs_log(LP_NOTICE,
                    103:                                    "use '%s commit' to remove %s "
                    104:                                    "permanently", __progname, (removed > 1) ?
                    105:                                    "these files" : "this file");
                    106:                        }
                    107:                }
1.49      joris     108:        }
                    109:
1.18      joris     110:        return (0);
                    111: }
                    112:
1.46      joris     113: void
                    114: cvs_remove_local(struct cvs_file *cf)
1.18      joris     115: {
1.46      joris     116:        int l;
                    117:        CVSENTRIES *entlist;
                    118:        char *entry, buf[MAXPATHLEN], tbuf[32], rbuf[16];
1.20      xsa       119:
1.46      joris     120:        cvs_log(LP_TRACE, "cvs_remove_local(%s)", cf->file_path);
1.20      xsa       121:
1.46      joris     122:        if (cf->file_type == CVS_DIR) {
1.19      xsa       123:                if (verbosity > 1)
1.46      joris     124:                        cvs_log(LP_NOTICE, "Removing %s", cf->file_path);
                    125:                return;
1.19      xsa       126:        }
                    127:
1.50      joris     128:        cvs_file_classify(cf, NULL, 0);
1.51      joris     129:
                    130:        if (cf->file_status == FILE_UNKNOWN) {
                    131:                if (verbosity > 1)
                    132:                        cvs_log(LP_NOTICE, "nothing known about '%s'",
                    133:                            cf->file_path);
                    134:                return;
                    135:        }
1.20      xsa       136:
1.56      xsa       137:        if (force_remove == 1 && cvs_noexec == 0) {
1.46      joris     138:                if (unlink(cf->file_path) == -1)
                    139:                        fatal("cvs_remove_local: %s", strerror(errno));
                    140:                (void)close(cf->fd);
                    141:                cf->fd = -1;
1.20      xsa       142:        }
                    143:
1.46      joris     144:        if (cf->fd != -1) {
                    145:                if (verbosity > 1)
                    146:                        cvs_log(LP_ERR, "file `%s' still in working directory",
                    147:                            cf->file_name);
1.20      xsa       148:                existing++;
                    149:        } else {
1.58    ! joris     150:                switch (cf->file_status) {
1.46      joris     151:                case FILE_ADDED:
                    152:                        entlist = cvs_ent_open(cf->file_wd);
                    153:                        cvs_ent_remove(entlist, cf->file_name);
                    154:                        cvs_ent_close(entlist, ENT_SYNC);
                    155:
                    156:                        l = snprintf(buf, sizeof(buf), "%s/%s/%s%s",
                    157:                            cf->file_path, CVS_PATH_CVSDIR, cf->file_name,
                    158:                            CVS_DESCR_FILE_EXT);
                    159:                        if (l == -1 || l >= (int)sizeof(buf))
                    160:                                fatal("cvs_remove_local: overflow");
                    161:
                    162:                        (void)unlink(buf);
                    163:
                    164:                        if (verbosity > 1) {
                    165:                                cvs_log(LP_NOTICE, "removed `%s'",
                    166:                                    cf->file_name);
                    167:                        }
                    168:                        return;
                    169:                case FILE_REMOVED:
1.58    ! joris     170:                        if (verbosity > 0) {
1.46      joris     171:                                cvs_log(LP_ERR,
                    172:                                    "file `%s' already scheduled for removal",
                    173:                                    cf->file_name);
                    174:                        }
                    175:                        return;
                    176:                default:
                    177:                        rcsnum_tostr(cf->file_ent->ce_rev, rbuf,
                    178:                             sizeof(rbuf));
1.34      xsa       179:
1.46      joris     180:                        ctime_r(&cf->file_ent->ce_mtime, tbuf);
                    181:                        if (tbuf[strlen(tbuf) - 1] == '\n')
                    182:                                tbuf[strlen(tbuf) - 1] = '\0';
                    183:
                    184:                        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    185:                        l = snprintf(entry, CVS_ENT_MAXLINELEN,
                    186:                             "/%s/-%s/%s//", cf->file_name, rbuf, tbuf);
                    187:                        if (l == -1 || l >= CVS_ENT_MAXLINELEN)
                    188:                                fatal("cvs_remove_local: overflow");
                    189:
1.58    ! joris     190:                        if (cvs_server_active == 1) {
        !           191:                                cvs_server_update_entry("Checked-in", cf);
        !           192:                                cvs_remote_output(entry);
        !           193:                        } else {
        !           194:                                entlist = cvs_ent_open(cf->file_wd);
        !           195:                                cvs_ent_add(entlist, entry);
        !           196:                                cvs_ent_close(entlist, ENT_SYNC);
        !           197:                        }
1.46      joris     198:
                    199:                        xfree(entry);
                    200:
1.58    ! joris     201:                        if (verbosity > 0) {
1.46      joris     202:                                cvs_log(LP_NOTICE,
                    203:                                    "scheduling file `%s' for removal",
                    204:                                    cf->file_name);
                    205:                        }
1.34      xsa       206:
1.46      joris     207:                        cf->file_status = FILE_REMOVED;
                    208:                        removed++;
                    209:                        break;
                    210:                }
1.20      xsa       211:        }
1.1       xsa       212: }