* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#define _GNU_SOURCE
-#include <babeltrace/context.h>
-#include <babeltrace/iterator.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <babeltrace/compat/dirent-internal.h>
+#include <babeltrace/compat/limits-internal.h>
+#include <sys/stat.h>
-struct bt_context *create_context_with_path(const char *path)
+void recursive_rmdir(const char *path)
{
- struct bt_context *ctx;
- int ret;
+ struct dirent *entry;
+ DIR *dir = opendir(path);
- ctx = bt_context_create();
- if (!ctx) {
- return NULL;
+ if (!dir) {
+ perror("# opendir");
+ return;
}
- ret = bt_context_add_trace(ctx, path, "ctf", NULL, NULL, NULL);
- if (ret < 0) {
- bt_context_put(ctx);
- return NULL;
+ while ((entry = readdir(dir))) {
+ struct stat st;
+ char filename[PATH_MAX];
+
+ if (snprintf(filename, sizeof(filename), "%s/%s",
+ path, entry->d_name) <= 0) {
+ continue;
+ }
+
+ if (stat(filename, &st)) {
+ continue;
+ }
+
+ if (S_ISREG(st.st_mode)) {
+ unlinkat(bt_dirfd(dir), entry->d_name, 0);
+ }
}
- return ctx;
+
+ rmdir(path);
+ closedir(dir);
}