Refactor local helper function, change readdir() to recursive nftw()
@@ -194,29 +194,22 @@ static int cond_checkpath(const char *path)
return 0;
}
-/* Intended for 'service/foo/`, nothing else */
-static void cond_delpath(const char *path)
+static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftw)
{
- char fn[PATH_MAX];
- struct dirent *d;
- DIR *dir;
+ if (ftw->level == 0)
+ return 1;
- dir = opendir(path);
- if (!dir)
- return;
+ if (remove(fpath))
+ err(1, "Failed removing condition %s", fpath);
- while ((d = readdir(dir))) {
- if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
- continue;
-
- paste(fn, sizeof(fn), path, d->d_name);
- if (remove(fn))
- err(1, "Failed removing condition path, file %s", fn);
+ return 0;
}
- closedir(dir);
- if (unlink(path) && errno != EISDIR)
- err(1, "Failed removing condition path %s", fn);
+static void cond_delpath(const char *path)
+{
+ nftw(path, do_delete, 20, FTW_DEPTH);
+ if (remove(path))
+ err(1, "Failed removing condition path %s", path);
}
int cond_set_path(const char *path, enum cond_state next)
