<commit_before>#include <sys/mount.h>
#include <limits.h>
#include <unistd.h>
#include <stdio.h>
#include "mosaic.h"
#include "status.h"

#define STATUS_DIR	"mosaic.status"

static int st_check_dir(void)
{
	if (!access(STATUS_DIR"/active", X_OK))
		return 0;

	if (mount("mosaic.status", STATUS_DIR, "tmpfs", 0, NULL)) {
		perror("Can't mount status dir");
		return 1;
	}

	/*
	 * FIXME -- record in mountinfo should be enough
	 */

	if (creat(STATUS_DIR"/active", 0600)) {
		perror("Can't create status dir");
		umount(STATUS_DIR);
		return 1;
	}

	return 0;
}

static char st_aux[PATH_MAX];

void st_set_mounted(struct mosaic *m, char *path)
{
	FILE *st;

	if (st_check_dir())
		return;

	/*
	 * FIXME -- this is YAML, but it's handled manually
	 * FIXME 2 -- several mounts
	 */

	sprintf(st_aux, STATUS_DIR "/m.%s", m->m_name);
	st = fopen(st_aux, "w");
	fprintf(st, "- %s\n", path);
	fclose(st);
}

char *st_get_mounted(struct mosaic *m)
{
	FILE *st;

	if (st_check_dir())
		return;

	/*
	 * FIXME -- not good to report static string back
	 */

	sprintf(st_aux, STATUS_DIR "/m.%s", m->m_name);
	st = fopen(st_aux, "r");
	if (!st)
		return "-";

	fgets(st_aux, sizeof(st_aux), st);
	fclose(st);

	if (st_aux[0] != '-' || st_aux[1] != ' ') {
		printf("Status for %s is screwed up\n", m->m_name);
		return "X";
	}
<commit_msg>Status file can be empty<commit_after>#include <sys/mount.h>
#include <limits.h>
#include <unistd.h>
#include <stdio.h>
#include "mosaic.h"
#include "status.h"

#define STATUS_DIR	"mosaic.status"

static int st_check_dir(void)
{
	int fd;

	if (!access(STATUS_DIR"/active", F_OK))
		return 0;

	if (mount("mosaic.status", STATUS_DIR, "tmpfs", 0, NULL)) {
		perror("Can't mount status dir");
		return 1;
	}

	/*
	 * FIXME -- record in mountinfo should be enough
	 */

	fd = creat(STATUS_DIR"/active", 0600);
	if (fd < 0) {
		perror("Can't create status dir");
		umount(STATUS_DIR);
		return 1;
	}

	close(fd);
	return 0;
}

static char st_aux[PATH_MAX];

void st_set_mounted(struct mosaic *m, char *path)
{
	FILE *st;

	if (st_check_dir())
		return;

	/*
	 * FIXME -- this is YAML, but it's handled manually
	 * FIXME 2 -- several mounts
	 */

	sprintf(st_aux, STATUS_DIR "/m.%s", m->m_name);
	st = fopen(st_aux, "w");
	fprintf(st, "- %s\n", path);
	fclose(st);
}

char *st_get_mounted(struct mosaic *m)
{
	FILE *st;
	char *s;

	if (st_check_dir())
		return "X";

	/*
	 * FIXME -- not good to report static string back
	 */

	sprintf(st_aux, STATUS_DIR "/m.%s", m->m_name);
	st = fopen(st_aux, "r");
	if (!st)
		return "no";

	s = fgets(st_aux, sizeof(st_aux), st);
	fclose(st);

	if (!s)
		return "no";

	if (st_aux[0] != '-' || st_aux[1] != ' ') {
		printf("Status for %s is screwed up\n", m->m_name);
		return "X";
	}

{'fraction_non_alphanumeric': 0.18383691299599564, 'fraction_numerical': 0.009100837277029487, 'mean_word_length': 3.610738255033557, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, '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': '2779492', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1136, 'n_words': 287}