#include "cvs.h"
#ifdef CLIENT_SUPPORT
static int remove_force_fileproc PROTO ((void *callerdat,
struct file_info *finfo));
#endif
static int remove_fileproc PROTO ((void *callerdat, struct file_info *finfo));
static Dtype remove_dirproc PROTO ((void *callerdat, char *dir,
char *repos, char *update_dir,
List *entries));
static int force;
static int local;
static int removed_files;
static int existing_files;
static const char *const remove_usage[] =
{
"Usage: %s %s [-flR] [files...]\n",
"\t-f\tDelete the file before removing it.\n",
"\t-l\tProcess this directory only (not recursive).\n",
"\t-R\tProcess directories recursively.\n",
"(Specify the --help global option for a list of other help options)\n",
NULL
};
int
cvsremove (argc, argv)
int argc;
char **argv;
{
int c, err;
if (argc == -1)
usage (remove_usage);
optind = 0;
while ((c = getopt (argc, argv, "+flR")) != -1)
{
switch (c)
{
case 'f':
force = 1;
break;
case 'l':
local = 1;
break;
case 'R':
local = 0;
break;
case '?':
default:
usage (remove_usage);
break;
}
}
argc -= optind;
argv += optind;
wrap_setup ();
#ifdef CLIENT_SUPPORT
if (client_active) {
expand_wild (argc, argv, &argc, &argv);
if (force)
{
if (!noexec)
{
start_recursion (remove_force_fileproc, (FILESDONEPROC) NULL,
(DIRENTPROC) NULL, (DIRLEAVEPROC) NULL,
(void *) NULL, argc, argv, local, W_LOCAL,
0, 0, (char *) NULL, 0);
}
}
start_server ();
ign_setup ();
if (local)
send_arg("-l");
send_file_names (argc, argv, 0);
send_files (argc, argv, local, 0, 0);
send_to_server ("remove\012", 0);
return get_responses_and_close ();
}
#endif
err = start_recursion (remove_fileproc, (FILESDONEPROC) NULL,
remove_dirproc, (DIRLEAVEPROC) NULL, NULL,
argc, argv,
local, W_LOCAL, 0, 1, (char *) NULL, 1);
if (removed_files)
error (0, 0, "use '%s commit' to remove %s permanently", program_name,
(removed_files == 1) ? "this file" : "these files");
if (existing_files)
error (0, 0,
((existing_files == 1) ?
"%d file exists; remove it first" :
"%d files exist; remove them first"),
existing_files);
return (err);
}
#ifdef CLIENT_SUPPORT
static int
remove_force_fileproc (callerdat, finfo)
void *callerdat;
struct file_info *finfo;
{
if (CVS_UNLINK (finfo->file) < 0 && ! existence_error (errno))
error (0, errno, "unable to remove %s", finfo->fullname);
return 0;
}
#endif
static int
remove_fileproc (callerdat, finfo)
void *callerdat;
struct file_info *finfo;
{
Vers_TS *vers;
if (force)
{
if (!noexec)
{
if ( CVS_UNLINK (finfo->file) < 0 && ! existence_error (errno))
{
error (0, errno, "unable to remove %s", finfo->fullname);
}
}
}
vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
if (vers->ts_user != NULL)
{
existing_files++;
if (!quiet)
error (0, 0, "file `%s' still in working directory",
finfo->fullname);
}
else if (vers->vn_user == NULL)
{
if (!quiet)
error (0, 0, "nothing known about `%s'", finfo->fullname);
}
else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
{
char *fname;
Scratch_Entry (finfo->entries, finfo->file);
fname = xmalloc (strlen (finfo->file)
+ sizeof (CVSADM)
+ sizeof (CVSEXT_LOG)
+ 10);
(void) sprintf (fname, "%s/%s%s", CVSADM, finfo->file, CVSEXT_LOG);
(void) unlink_file (fname);
if (!quiet)
error (0, 0, "removed `%s'", finfo->fullname);
#ifdef SERVER_SUPPORT
if (server_active)
server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
#endif
free (fname);
}
else if (vers->vn_user[0] == '-')
{
if (!quiet)
error (0, 0, "file `%s' already scheduled for removal",
finfo->fullname);
}
else if (vers->tag != NULL && isdigit (*vers->tag))
{
error (0, 0, "\
cannot remove file `%s' which has a numeric sticky tag of `%s'",
finfo->fullname, vers->tag);
}
else
{
char *fname;
fname = xmalloc (strlen (vers->vn_user) + 5);
(void) strcpy (fname, "-");
(void) strcat (fname, vers->vn_user);
Register (finfo->entries, finfo->file, fname, vers->ts_rcs, vers->options,
vers->tag, vers->date, vers->ts_conflict);
if (!quiet)
error (0, 0, "scheduling `%s' for removal", finfo->fullname);
removed_files++;
#ifdef SERVER_SUPPORT
if (server_active)
server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
#endif
free (fname);
}
freevers_ts (&vers);
return (0);
}
static Dtype
remove_dirproc (callerdat, dir, repos, update_dir, entries)
void *callerdat;
char *dir;
char *repos;
char *update_dir;
List *entries;
{
if (!quiet)
error (0, 0, "Removing %s", update_dir);
return (R_PROCESS);
}