<commit_before>// Copyright (c) 2013, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.

#include <iostream>
#include <nix/file/Directory.hpp>
#include "../../include/nix/file/Directory.hpp"
#include "../../include/nix/base/IFile.hpp"

using namespace std;

using namespace boost::filesystem;

namespace nix {
namespace file {

Directory::Directory(const path &location, FileMode mode)
    : loc(location), mode(mode) {
    open_or_create();
    attributes = AttributesFS(loc, mode);
}

Directory::Directory(const string &location, FileMode mode): Directory(path(location.c_str()), mode) {}

void Directory::open_or_create() {
   // path temp = current_path();
   // current_path(parent);
    if (!exists(loc)) {
        if (mode > FileMode::ReadOnly) {
            create_directories(loc);
        } else {
            throw std::logic_error("Trying to create new directory in ReadOnly mode!");
        }
    }
    // current_path(temp);
}

bool Directory::hasAttr(const string &name) const  {
    return attributes.has(name);
}

void Directory::removeAttr(const string &name) {
    attributes.remove(name);
}

string Directory::location() const {
    return loc.string();
}

} // nix::file
} // nix<commit_msg>[file_backend/Directory] cleanup<commit_after>// Copyright (c) 2013, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.

#include <iostream>
#include <nix/file/Directory.hpp>
#include "../../include/nix/file/Directory.hpp"
#include "../../include/nix/base/IFile.hpp"

using namespace std;

using namespace boost::filesystem;

namespace nix {
namespace file {

Directory::Directory(const path &location, FileMode mode)
    : loc(location), mode(mode) {
    open_or_create();
    attributes = AttributesFS(loc, mode);
}

Directory::Directory(const string &location, FileMode mode): Directory(path(location.c_str()), mode) {}

void Directory::open_or_create() {
    if (!exists(loc)) {
        if (mode > FileMode::ReadOnly) {
            create_directories(loc);
        } else {
            throw std::logic_error("Trying to create new directory in ReadOnly mode!");
        }
    }
}

bool Directory::hasAttr(const string &name) const  {
    return attributes.has(name);
}

void Directory::removeAttr(const string &name) {
    attributes.remove(name);
}

string Directory::location() const {
    return loc.string();
}

} // nix::file
} // nix
{'fraction_non_alphanumeric': 0.13804347826086957, 'fraction_numerical': 0.002898550724637681, 'mean_word_length': 3.6016666666666666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6922968', 'n_tokens_mistral': 834, 'n_tokens_neox': 806, 'n_words': 233}