<commit_before>#include "fileinfo.hpp"
#include "fileinfo_service.hpp"

namespace x0 {

fileinfo::fileinfo(fileinfo_service& service, const std::string& filename) :
	service_(service),
	watcher_(service.loop_),
	filename_(filename),
	exists_(),
	etag_(service_.make_etag(*this)),
	mtime_(),
	mimetype_(service_.get_mimetype(filename_))
{
	watcher_.set<fileinfo, &fileinfo::callback>(this);
	watcher_.set(filename_.c_str());
	watcher_.start();

	exists_ = watcher_.attr.st_nlink > 0;
}


void fileinfo::callback(ev::stat& w, int revents)
{
	data_.clear();

	etag_ = service_.make_etag(*this);
	mimetype_ = service_.get_mimetype(filename_);
}

} // namespace x0<commit_msg>fixed bug where mtime-cache did not get cleared/updated when file changed<commit_after>#include "fileinfo.hpp"
#include "fileinfo_service.hpp"

namespace x0 {

fileinfo::fileinfo(fileinfo_service& service, const std::string& filename) :
	service_(service),
	watcher_(service.loop_),
	filename_(filename),
	exists_(),
	etag_(service_.make_etag(*this)),
	mtime_(),
	mimetype_(service_.get_mimetype(filename_))
{
	watcher_.set<fileinfo, &fileinfo::callback>(this);
	watcher_.set(filename_.c_str());
	watcher_.start();

	exists_ = watcher_.attr.st_nlink > 0;
}


void fileinfo::callback(ev::stat& w, int revents)
{
	data_.clear();

	etag_ = service_.make_etag(*this);
	mtime_.clear(); // gets computed on-demand
	mimetype_ = service_.get_mimetype(filename_);
}

} // namespace x0
{'fraction_non_alphanumeric': 0.15283540802213003, 'fraction_numerical': 0.004149377593360996, 'mean_word_length': 6.4974093264248705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5769944', 'n_tokens_mistral': 530, 'n_tokens_neox': 520, 'n_words': 87}