From 5f50c7fb1e7ce0d2f912b2fcb92c1dc7ed443c58 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Wed, 21 Mar 2012 10:40:05 +0100 Subject: [PATCH] Add remove_dir function into the misc --- src/misc.c | 26 ++++++++++++++++++++++++++ src/misc.h | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/misc.c b/src/misc.c index 2a531c5..5052e34 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,9 +1,13 @@ +#define _XOPEN_SOURCE 500 + #include #include #include #include #include #include +#include +#include #include "logging.h" #include "constants.h" #include "misc.h" @@ -14,6 +18,8 @@ #define BUFFER_SIZE 4096 +#define UNUSED(x) (void)(x) // Used to suppress compiler warning about unused param + const char *flag_to_string(gint64 flags) { @@ -420,6 +426,7 @@ int copy_file(const char *src, const char *dst) return CR_COPY_OK; } + /* long int get_file_size(const char *path) { @@ -443,3 +450,22 @@ long int get_file_size(const char *path) return size; } */ + + +int remove_dir_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) +{ + UNUSED(sb); + UNUSED(typeflag); + UNUSED(ftwbuf); + int rv = remove(fpath); + if (rv) + g_critical("%s: Cannot remove: %s: %s", __func__, fpath, strerror(errno)); + + return rv; +} + + +int remove_dir(const char *path) +{ + return nftw(path, remove_dir_cb, 64, FTW_DEPTH | FTW_PHYS); +} diff --git a/src/misc.h b/src/misc.h index 38a69cc..d7b5764 100644 --- a/src/misc.h +++ b/src/misc.h @@ -36,6 +36,6 @@ char *get_filename(const char *filepath); #define CR_COPY_ERR 1 int copy_file(const char *src, const char *dst); - +int remove_dir(const char *path); #endif /* __C_CREATEREPOLIB_MISC_H__ */ -- 2.7.4