mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-31 13:03:02 +02:00
Add new helper function rmrf
for recursive delete of directories
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* XXX: removed.
|
||||
*/
|
||||
|
||||
#include <ftw.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
@@ -13,6 +14,7 @@
|
||||
#include <sys/wait.h>
|
||||
#include <libite/lite.h>
|
||||
|
||||
#include "common.h"
|
||||
int debug; /* Sets debug level (0:off) */
|
||||
|
||||
/* TODO remove once confd / statd lib situation is resolved */
|
||||
@@ -20,6 +22,29 @@ int debug; /* Sets debug level (0:off) */
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap);
|
||||
#endif
|
||||
|
||||
static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftw)
|
||||
{
|
||||
if (ftw->level == 0)
|
||||
return 1;
|
||||
|
||||
if (remove(fpath) && errno != EBUSY)
|
||||
WARN("Failed removing %s", fpath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rmrf(const char *path)
|
||||
{
|
||||
if (!fisdir(path))
|
||||
return 0;
|
||||
|
||||
nftw(path, do_delete, 64, FTW_DEPTH | FTW_PHYS);
|
||||
if (remove(path) && errno != ENOENT)
|
||||
WARN("Failed removing path %s", path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *unquote(char *buf)
|
||||
{
|
||||
char q = buf[0];
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap);
|
||||
|
||||
int rmrf(const char *path);
|
||||
char *unquote(char *buf);
|
||||
char *fgetkey(const char *file, const char *key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user