Changeset: a38c9a598c8c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a38c9a598c8c Modified Files: tools/merovingian/utils/database.c tools/merovingian/utils/utils.c tools/merovingian/utils/utils.h Branch: hot-snapshot Log Message:
Move deletdir to util.c diffs (145 lines): diff --git a/tools/merovingian/utils/database.c b/tools/merovingian/utils/database.c --- a/tools/merovingian/utils/database.c +++ b/tools/merovingian/utils/database.c @@ -138,54 +138,6 @@ char* db_create(char* dbname) { return(NULL); } -/* recursive helper function to delete a directory */ -static char* deletedir(const char *dir) { - DIR *d; - struct dirent *e; - char buf[8192]; - char path[4096]; - - d = opendir(dir); - if (d == NULL) { - /* silently return if we cannot find the directory; it's - * probably already deleted */ - if (errno == ENOENT) - return(NULL); - if (errno == ENOTDIR) { - if (remove(dir) != 0 && errno != ENOENT) { - snprintf(buf, sizeof(buf), - "unable to remove file %s: %s", - dir, strerror(errno)); - return(strdup(buf)); - } - return NULL; - } - snprintf(buf, sizeof(buf), "unable to open dir %s: %s", - dir, strerror(errno)); - return(strdup(buf)); - } - while ((e = readdir(d)) != NULL) { - /* ignore . and .. */ - if (strcmp(e->d_name, ".") != 0 && - strcmp(e->d_name, "..") != 0) { - char* er; - snprintf(path, sizeof(path), "%s/%s", dir, e->d_name); - if ((er = deletedir(path)) != NULL) { - closedir(d); - return(er); - } - } - } - closedir(d); - if (rmdir(dir) == -1 && errno != ENOENT) { - snprintf(buf, sizeof(buf), "unable to remove directory %s: %s", - dir, strerror(errno)); - return(strdup(buf)); - } - - return(NULL); -} - char* db_destroy(char* dbname) { sabdb* stats; char* e; diff --git a/tools/merovingian/utils/utils.c b/tools/merovingian/utils/utils.c --- a/tools/merovingian/utils/utils.c +++ b/tools/merovingian/utils/utils.c @@ -19,12 +19,10 @@ #include "utils.h" #include <unistd.h> /* unlink */ #include <string.h> /* memcpy */ -#include <strings.h> /* strcasecmp */ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> #include <time.h> #include <ctype.h> +#include <dirent.h> /* readdir */ +#include <fcntl.h> #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -488,4 +486,56 @@ sleep_ms(size_t ms) (void) select(0, NULL, NULL, NULL, &tv); } + +/* recursive helper function to delete a directory */ +char* +deletedir(const char *dir) +{ + DIR *d; + struct dirent *e; + char buf[8192]; + char path[4096]; + + d = opendir(dir); + if (d == NULL) { + /* silently return if we cannot find the directory; it's + * probably already deleted */ + if (errno == ENOENT) + return(NULL); + if (errno == ENOTDIR) { + if (remove(dir) != 0 && errno != ENOENT) { + snprintf(buf, sizeof(buf), + "unable to remove file %s: %s", + dir, strerror(errno)); + return(strdup(buf)); + } + return NULL; + } + snprintf(buf, sizeof(buf), "unable to open dir %s: %s", + dir, strerror(errno)); + return(strdup(buf)); + } + while ((e = readdir(d)) != NULL) { + /* ignore . and .. */ + if (strcmp(e->d_name, ".") != 0 && + strcmp(e->d_name, "..") != 0) { + char* er; + snprintf(path, sizeof(path), "%s/%s", dir, e->d_name); + if ((er = deletedir(path)) != NULL) { + closedir(d); + return(er); + } + } + } + closedir(d); + if (rmdir(dir) == -1 && errno != ENOENT) { + snprintf(buf, sizeof(buf), "unable to remove directory %s: %s", + dir, strerror(errno)); + return(strdup(buf)); + } + + return(NULL); +} + + /* vim:set ts=4 sw=4 noexpandtab: */ diff --git a/tools/merovingian/utils/utils.h b/tools/merovingian/utils/utils.h --- a/tools/merovingian/utils/utils.h +++ b/tools/merovingian/utils/utils.h @@ -43,6 +43,8 @@ void abbreviateString(char *ret, const c void generateSalt(char *buf, unsigned int len); char *generatePassphraseFile(const char *path); void sleep_ms(size_t ms); +char* deletedir(const char *dir); + #endif _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list