<commit_before>#include <limits.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "tree.h"
#include "config.h"

bool tree_create(const char *name) {
	/* the return value */
	bool is_success = false;

	/* the directory path */
	char path[PATH_MAX];

	/* the directory */
	DIR *directory;

	/* the directory attributes */
	struct stat attributes;

	/* a file under the directory */
	struct dirent _entry;
	struct dirent *entry;

	/* a sub-directory path */
	char sub_directory[PATH_MAX];

	/* get the directory attributes */
	(void) snprintf((char *) &path,
	                sizeof(path),
	                "%s/%s",
	                CONFIG_READ_ONLY_DIRECTORY,
	                name);
	if (-1 == stat((char *) &path, &attributes))
		goto end;

	/* open the directory */
	directory = opendir(path);
	if (NULL == directory)
		goto end;

	/* create the directory, under the writeable branch */
	(void) snprintf((char *) &path,
	                sizeof(path),
	                "%s/%s",
	                CONFIG_WRITEABLE_DIRECTORY,
	                name);
	if (-1 == mkdir((char *) &path, attributes.st_mode)) {
		if (EEXIST != errno)
			goto close_directory;
	}

	do {
		/* read the details of a file under the directory */
		if (0 != readdir_r(directory, &_entry, &entry))
			goto close_directory;
		if (NULL == entry)
			break;

		/* skip non-directory entries */
		if (DT_DIR != entry->d_type)
			continue;

		/* skip relative paths */
		if ((0 == strcmp(".", (char *) &entry->d_name)) ||
		    (0 == strcmp("..", (char *) &entry->d_name)))
			continue;

		/* recurse into sub-directories */
		(void) snprintf((char *) &sub_directory,
		                sizeof(sub_directory),
		                "%s/%s",
		                name,
		                (char *) &entry->d_name);
		if (false == tree_create((char *) &sub_directory))
			goto close_directory;
	} while (1);

	/* report success */
	is_success = true;

close_directory:
	/* close the directory */
	(void) closedir(directory);<commit_msg>Bug fix - use only one path in tree_create().<commit_after>#include <limits.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "tree.h"
#include "config.h"

bool tree_create(const char *name) {
	/* the return value */
	bool is_success = false;

	/* the directory path */
	char path[PATH_MAX];

	/* the directory */
	DIR *directory;

	/* the directory attributes */
	struct stat attributes;

	/* a file under the directory */
	struct dirent _entry;
	struct dirent *entry;

	/* get the directory attributes */
	(void) snprintf((char *) &path,
	                sizeof(path),
	                "%s/%s",
	                CONFIG_READ_ONLY_DIRECTORY,
	                name);
	if (-1 == stat((char *) &path, &attributes))
		goto end;

	/* open the directory */
	directory = opendir(path);
	if (NULL == directory)
		goto end;

	/* create the directory, under the writeable branch */
	(void) snprintf((char *) &path,
	                sizeof(path),
	                "%s/%s",
	                CONFIG_WRITEABLE_DIRECTORY,
	                name);
	if (-1 == mkdir((char *) &path, attributes.st_mode)) {
		if (EEXIST != errno)
			goto close_directory;
	}

	do {
		/* read the details of a file under the directory */
		if (0 != readdir_r(directory, &_entry, &entry))
			goto close_directory;
		if (NULL == entry)
			break;

		/* skip non-directory entries */
		if (DT_DIR != entry->d_type)
			continue;

		/* skip relative paths */
		if ((0 == strcmp(".", (char *) &entry->d_name)) ||
		    (0 == strcmp("..", (char *) &entry->d_name)))
			continue;

		/* recurse into sub-directories */
		(void) snprintf((char *) &path,
		                sizeof(path),
		                "%s/%s",
		                name,
		                (char *) &entry->d_name);
		if (false == tree_create((char *) &path))
			goto close_directory;
	} while (1);

	/* report success */
	is_success = true;

close_directory:
	/* close the directory */
	(void) closedir(directory);
{'fraction_non_alphanumeric': 0.15459171310879574, 'fraction_numerical': 0.002907681124303368, 'mean_word_length': 2.4457429048414023, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, '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': '1123655', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1315, 'n_words': 367}