<commit_before>import { spawnBashScriptSync } from './spawnBash';

enum validatePathResult {
	success = 0,
	notExistCwd,
	notFoundBash,
	notFoundBashdb,
	notFoundCat,
	notFoundMkfifo,
	notFoundPkill,
	timeout,
	cannotChmod,
	unsupportedBashVersion,
	unknown,
}

/**
 * @example
 * _validatePath("./", "bash", "type", "type", "type", "type");
 * // => validatePathResult.success
 *
 * @example
 * _validatePath("non-exist-directory", "bash", "type", "type", "type", "type");
 * // => validatePathResult.notExistCwd
 *
 * @example
 * _validatePath("./", "invalid-bash-path", "type", "type", "type", "type");
 * // => validatePathResult.notFoundBash
 *
 * @example
 * _validatePath("./", "bash", "invalid-bashdb-path", "type", "type", "type");
 * // => validatePathResult.notFoundBashdb
 *
 * @example
 * _validatePath("./", "bash", "type", "invalid-cat-path", "type", "type");
 * // => validatePathResult.notFoundCat
 *
 * @example
 * _validatePath("./", "bash", "type", "type", "invalid-mkfifo-path", "type");
 * // => validatePathResult.notFoundMkfifo
 *
 * @example
 * _validatePath("./", "bash", "type", "type", "type", "invalid-pkill-path");
 * // => validatePathResult.notFoundPkill
 *
 * @example
 * _validatePath("./", "bash", "type", "type", "type", "invalid-pkill-path");
 * // => validatePathResult.notFoundPkill
 *
 * @example
 * _validatePath("invalid-path", "invalid-path", "invalid-path", "invalid-path", "invalid-path", "invalid-path");
 * // => validatePathResult.notFoundBash
 *
 * @example
 * _validatePath("./", "bash", "", "", "", "", 1);
 * // => validatePathResult.timeout
 */
function _validatePath(cwd: string,
	pathBash: string, pathBashdb: string, pathCat: string, pathMkfifo: string, pathPkill: string, spawnTimeout: number = 5000): [validatePathResult, string] {

	const vpr = validatePathResult;

	const proc = spawnBashScriptSync(
		((pathBashdb.indexOf("bashdb_dir") > 0) ? `chmod +x "${pathBashdb}" || exit ${vpr.cannotChmod};` : ``) +<commit_msg>fix: Avoid chmod bashdb if it is already executable.<commit_after>import { spawnBashScriptSync } from './spawnBash';
import * as fs from 'fs';

enum validatePathResult {
	success = 0,
	notExistCwd,
	notFoundBash,
	notFoundBashdb,
	notFoundCat,
	notFoundMkfifo,
	notFoundPkill,
	timeout,
	cannotChmod,
	unsupportedBashVersion,
	unknown,
}

/**
 * @example
 * _validatePath("./", "bash", "type", "type", "type", "type");
 * // => validatePathResult.success
 *
 * @example
 * _validatePath("non-exist-directory", "bash", "type", "type", "type", "type");
 * // => validatePathResult.notExistCwd
 *
 * @example
 * _validatePath("./", "invalid-bash-path", "type", "type", "type", "type");
 * // => validatePathResult.notFoundBash
 *
 * @example
 * _validatePath("./", "bash", "invalid-bashdb-path", "type", "type", "type");
 * // => validatePathResult.notFoundBashdb
 *
 * @example
 * _validatePath("./", "bash", "type", "invalid-cat-path", "type", "type");
 * // => validatePathResult.notFoundCat
 *
 * @example
 * _validatePath("./", "bash", "type", "type", "invalid-mkfifo-path", "type");
 * // => validatePathResult.notFoundMkfifo
 *
 * @example
 * _validatePath("./", "bash", "type", "type", "type", "invalid-pkill-path");
 * // => validatePathResult.notFoundPkill
 *
 * @example
 * _validatePath("./", "bash", "type", "type", "type", "invalid-pkill-path");
 * // => validatePathResult.notFoundPkill
 *
 * @example
 * _validatePath("invalid-path", "invalid-path", "invalid-path", "invalid-path", "invalid-path", "invalid-path");
 * // => validatePathResult.notFoundBash
 *
 * @example
 * _validatePath("./", "bash", "", "", "", "", 1);
 * // => validatePathResult.timeout
 */
function _validatePath(cwd: string,
	pathBash: string, pathBashdb: string, pathCat: string, pathMkfifo: string, pathPkill: string, spawnTimeout: number = 5000): [validatePathResult, string] {

	const vpr = validatePathResult;


	var chmod_bashdb = pathBashdb.indexOf("bashdb_dir") > 0;
	if (chmod_bashdb) {
	    try {
		fs.accessSync( pathBashdb, fs.constants.X_OK );
		chmod_bashdb = false;
	    } catch ( err ) {
		// Means that execute not possible, try and chmod it
	    }
	}

	const proc = spawnBashScriptSync(
		((chmod_bashdb) ? `chmod +x "${pathBashdb}" || exit ${vpr.cannotChmod};` : ``) +
{'fraction_non_alphanumeric': 0.20465772759350742, 'fraction_numerical': 0.003293342742884027, 'mean_word_length': 4.631788079470199, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5351818', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1469, 'n_words': 287}