#include "rspamdclient.h"
#include "utlist.h"
#include "unix-std.h"
-
-#include <fts.h>
-
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd,
const gchar *name, GQueue *attrs)
{
- FTS *fts;
- FTSENT *entry;
+ DIR *d;
+ struct dirent entry, *pentry = NULL;
gint cur_req = 0;
+ gchar fpath[PATH_MAX];
FILE *in;
+ struct stat st;
- gchar * const names[] = {
- (gchar *)name,
- NULL
- };
+ memset (&entry, 0, sizeof (entry));
+ d = opendir (name);
- fts = fts_open (&names[0], FTS_LOGICAL|FTS_XDEV, NULL);
+ if (d != NULL) {
+ while (readdir_r (d, &entry, &pentry) == 0) {
+ if (pentry == NULL) {
+ break;
+ }
- if (fts != NULL) {
- while ((entry = fts_read (fts))) {
- if (entry->fts_info != FTS_F) {
+ if (pentry->d_name[0] == '.') {
continue;
}
- in = fopen (entry->fts_path, "r");
- if (in == NULL) {
- rspamd_fprintf (stderr, "cannot open file %s: %s\n",
- entry->fts_path, strerror (errno));
+ rspamd_snprintf (fpath, sizeof (fpath), "%s%c%s",
+ name, G_DIR_SEPARATOR, pentry->d_name);
+
+ if (lstat (fpath, &st) == -1) {
+ rspamd_fprintf (stderr, "cannot stat file %s: %s\n",
+ fpath, strerror (errno));
+ continue;
+ }
+
+ if (S_ISDIR (st.st_mode)) {
+ rspamc_process_dir (ev_base, cmd, fpath, attrs);
continue;
}
+ else if (S_ISREG (st.st_mode)) {
+ in = fopen (fpath, "r");
+ if (in == NULL) {
+ rspamd_fprintf (stderr, "cannot open file %s: %s\n",
+ fpath, strerror (errno));
+ continue;
+ }
- rspamc_process_input (ev_base, cmd, in, entry->fts_path, attrs);
- cur_req++;
- fclose (in);
+ rspamc_process_input (ev_base, cmd, in, fpath, attrs);
+ cur_req++;
+ fclose (in);
- if (cur_req >= max_requests) {
- cur_req = 0;
- /* Wait for completion */
- event_base_loop (ev_base, 0);
+ if (cur_req >= max_requests) {
+ cur_req = 0;
+ /* Wait for completion */
+ event_base_loop (ev_base, 0);
+ }
}
}
}
exit (EXIT_FAILURE);
}
- fts_close (fts);
+ closedir (d);
event_base_loop (ev_base, 0);
}