1993-08-05 18:28:27 +00:00
|
|
|
|
/* srmdir.c
|
|
|
|
|
Remove a directory and all its contents.
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1992 Ian Lance Taylor
|
|
|
|
|
|
|
|
|
|
This file is part of the Taylor UUCP package.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
1995-08-19 21:30:30 +00:00
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1993-08-05 18:28:27 +00:00
|
|
|
|
|
|
|
|
|
The author of the program may be contacted at ian@airs.com or
|
1995-08-19 21:30:30 +00:00
|
|
|
|
c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
|
1993-08-05 18:28:27 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "uucp.h"
|
|
|
|
|
|
|
|
|
|
#include "uudefs.h"
|
|
|
|
|
#include "sysdep.h"
|
|
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#if HAVE_FTW_H
|
|
|
|
|
#include <ftw.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
1994-05-07 18:14:43 +00:00
|
|
|
|
static int isremove_dir P((const char *, struct stat *, int));
|
1993-08-05 18:28:27 +00:00
|
|
|
|
|
|
|
|
|
/* Keep a list of directories to be removed. */
|
|
|
|
|
|
|
|
|
|
struct sdirlist
|
|
|
|
|
{
|
|
|
|
|
struct sdirlist *qnext;
|
|
|
|
|
char *zdir;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct sdirlist *qSdirlist;
|
|
|
|
|
|
|
|
|
|
/* Remove a directory and all files in it. */
|
|
|
|
|
|
|
|
|
|
boolean
|
|
|
|
|
fsysdep_rmdir (zdir)
|
|
|
|
|
const char *zdir;
|
|
|
|
|
{
|
|
|
|
|
boolean fret;
|
|
|
|
|
struct sdirlist *q;
|
|
|
|
|
|
|
|
|
|
qSdirlist = NULL;
|
|
|
|
|
|
|
|
|
|
fret = TRUE;
|
|
|
|
|
if (ftw ((char *) zdir, isremove_dir, 5) != 0)
|
|
|
|
|
{
|
|
|
|
|
ulog (LOG_ERROR, "ftw: %s", strerror (errno));
|
|
|
|
|
fret = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
q = qSdirlist;
|
|
|
|
|
while (q != NULL)
|
|
|
|
|
{
|
|
|
|
|
struct sdirlist *qnext;
|
1995-08-19 21:30:30 +00:00
|
|
|
|
|
1993-08-05 18:28:27 +00:00
|
|
|
|
if (rmdir (q->zdir) != 0)
|
|
|
|
|
{
|
|
|
|
|
ulog (LOG_ERROR, "rmdir (%s): %s", q->zdir, strerror (errno));
|
|
|
|
|
fret = FALSE;
|
|
|
|
|
}
|
|
|
|
|
ubuffree (q->zdir);
|
|
|
|
|
qnext = q->qnext;
|
|
|
|
|
xfree ((pointer) q);
|
|
|
|
|
q = qnext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove a file in a directory. */
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
|
static int
|
|
|
|
|
isremove_dir (zfile, qstat, iflag)
|
|
|
|
|
const char *zfile;
|
1994-05-07 18:14:43 +00:00
|
|
|
|
struct stat *qstat;
|
1993-08-05 18:28:27 +00:00
|
|
|
|
int iflag;
|
|
|
|
|
{
|
|
|
|
|
if (iflag == FTW_D || iflag == FTW_DNR)
|
|
|
|
|
{
|
|
|
|
|
struct sdirlist *q;
|
|
|
|
|
|
|
|
|
|
q = (struct sdirlist *) xmalloc (sizeof (struct sdirlist));
|
|
|
|
|
q->qnext = qSdirlist;
|
|
|
|
|
q->zdir = zbufcpy (zfile);
|
|
|
|
|
qSdirlist = q;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (remove (zfile) != 0)
|
|
|
|
|
ulog (LOG_ERROR, "remove (%s): %s", zfile, strerror (errno));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|