<commit_before>#include <nix/file/FileFS.hpp>
#include <nix/file/BlockFS.hpp>
#include <nix/file/SectionFS.hpp>

using namespace std;
using namespace nix;

namespace fs = boost::filesystem;

namespace nix {
namespace file {

// Format definition
#define FILE_VERSION std::vector<int>{1, 0, 0}
#define FILE_FORMAT  std::string("nix")

static unsigned int map_file_mode(FileMode mode) {
    switch (mode) {
        case FileMode::ReadWrite:
            return ios::in | ios::out;

        case FileMode::ReadOnly:
            return ios::out;

        case FileMode::Overwrite:
            return ios::trunc;

        default:
            return ios::out;
    }
}


FileFS::FileFS(const string &name, FileMode mode)
    : DirectoryWithAttributes(name, mode){
    this->mode = mode;
    setCreatedAt();
    setUpdatedAt();
    create_subfolders();
    if (!checkHeader()) {
        throw std::runtime_error("Invalid file header: either file format or file version not correct");
    }
}
<commit_msg>[file_backend/File] upon opening in overwrite mode, remove all before<commit_after>#include <nix/file/FileFS.hpp>
#include <nix/file/BlockFS.hpp>
#include <nix/file/SectionFS.hpp>

using namespace std;
using namespace nix;

namespace fs = boost::filesystem;

namespace nix {
namespace file {

// Format definition
#define FILE_VERSION std::vector<int>{1, 0, 0}
#define FILE_FORMAT  std::string("nix")

static unsigned int map_file_mode(FileMode mode) {
    switch (mode) {
        case FileMode::ReadWrite:
            return ios::in | ios::out;

        case FileMode::ReadOnly:
            return ios::out;

        case FileMode::Overwrite:
            return ios::trunc;

        default:
            return ios::out;
    }
}


FileFS::FileFS(const string &name, FileMode mode)
    : DirectoryWithAttributes(name, mode){
    this->mode = mode;
    if (mode == FileMode::Overwrite) {
        removeAll();
    }
    setCreatedAt();
    setUpdatedAt();
    create_subfolders();
    if (!checkHeader()) {
        throw std::runtime_error("Invalid file header: either file format or file version not correct");
    }
}

{'fraction_non_alphanumeric': 0.1206244087038789, 'fraction_numerical': 0.002838221381267739, 'mean_word_length': 3.1389432485322897, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3175905', 'n_tokens_mistral': 664, 'n_tokens_neox': 639, 'n_words': 168}