<commit_before>/* $Id$ */

#undef _FILE_OFFSET_BITS	/* FTS is not 64-bit ready */

#include <sys/param.h>
#include <sys/stat.h>

#include <err.h>
#include <fts.h>
#include <stdio.h>
#include <stdlib.h>

#include "psc_ds/list.h"
#include "psc_ds/listcache.h"
#include "psc_util/ctlcli.h"
#include "psc_util/log.h"
#include "psc_util/strlcpy.h"

#include "mount_slash/ctl_cli.h"
#include "msctl.h"

void
walk(const char *fn, void (*cbf)(const char *, void *), void *arg)
{
	char * const pathv[] = { (char *)fn, NULL };
	char buf[PATH_MAX];
	struct stat stb;
	FTSENT *f;
	FTS *fp;

	if (recursive) {
		/* XXX security implications of FTS_NOCHDIR? */
		fp = fts_open(pathv, FTS_COMFOLLOW |
		    FTS_NOCHDIR | FTS_PHYSICAL, NULL);
		if (fp == NULL)
			psc_fatal("fts_open %s", fn);
		while ((f = fts_read(fp)) != NULL)
			if (S_ISREG(f->fts_statp->st_mode)) {
				if (realpath(f->fts_path, buf) == NULL)
					warn("%s", f->fts_path);
				else
					cbf(buf, arg);
			}
		fts_close(fp);
	} else {
		if (stat(fn, &stb) == -1)
			warn("%s", fn);
		else if (!S_ISREG(stb.st_mode))
			warnx("%s: not a regular file", fn);
		else if (realpath(fn, buf) == NULL)
			warn("%s", fn);
		else
			cbf(buf, arg);
	}
}<commit_msg>warn on certain types of fts_open failure, less confusing this way<commit_after>/* $Id$ */

#undef _FILE_OFFSET_BITS	/* FTS is not 64-bit ready */

#include <sys/param.h>
#include <sys/stat.h>

#include <err.h>
#include <fts.h>
#include <stdio.h>
#include <stdlib.h>

#include "psc_ds/list.h"
#include "psc_ds/listcache.h"
#include "psc_util/ctlcli.h"
#include "psc_util/log.h"
#include "psc_util/strlcpy.h"

#include "mount_slash/ctl_cli.h"
#include "msctl.h"

void
walk(const char *fn, void (*cbf)(const char *, void *), void *arg)
{
	char * const pathv[] = { (char *)fn, NULL };
	char buf[PATH_MAX];
	struct stat stb;
	FTSENT *f;
	FTS *fp;

	if (recursive) {
		/* XXX security implications of FTS_NOCHDIR? */
		fp = fts_open(pathv, FTS_COMFOLLOW |
		    FTS_NOCHDIR | FTS_PHYSICAL, NULL);
		if (fp == NULL)
			psc_fatal("fts_open %s", fn);
		while ((f = fts_read(fp)) != NULL) {
			if (f->fts_info & FTS_NS) {
				warn("%s", f->fts_path);
				continue;
			}
			if (S_ISREG(f->fts_statp->st_mode)) {
				if (realpath(f->fts_path, buf) == NULL)
					warn("%s", f->fts_path);
				else
					cbf(buf, arg);
			}
		}
		fts_close(fp);
	} else {
		if (stat(fn, &stb) == -1)
			warn("%s", fn);
		else if (!S_ISREG(stb.st_mode))
			warnx("%s: not a regular file", fn);
		else if (realpath(fn, buf) == NULL)
			warn("%s", fn);
		else
			cbf(buf, arg);
	}
}
{'fraction_non_alphanumeric': 0.1892103205629398, 'fraction_numerical': 0.0023455824863174357, 'mean_word_length': 3.569642857142857, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7076261', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1114, 'n_words': 258}