<commit_before>#include "CopyDir.h"
#include "CopyFile.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

#include "messmer/fspp/fuse/FuseErrnoException.h"
#include "CopyDevice.h"
#include "CopyOpenFile.h"

//TODO Get rid of this in favor of exception hierarchy
using fspp::fuse::CHECK_RETVAL;

namespace bf = boost::filesystem;

using std::unique_ptr;
using std::make_unique;
using std::string;
using std::vector;

namespace copyfs {

CopyDir::CopyDir(CopyDevice *device, const bf::path &path)
  :CopyNode(device, path) {
  assert(bf::is_directory(base_path()));
}

CopyDir::~CopyDir() {
}

unique_ptr<fspp::OpenFile> CopyDir::createAndOpenFile(const string &name, mode_t mode) {
  auto file_path = base_path() / name;
  //Create file
  int fd = ::creat(file_path.c_str(), mode);
  CHECK_RETVAL(fd);
  //TODO Don't close and reopen, that's inperformant
  ::close(fd);
  return make_unique<CopyOpenFile>(device(), path() / name, O_RDWR | O_TRUNC);
}

void CopyDir::createDir(const string &name, mode_t mode) {
  auto dir_path = base_path() / name;
  //Create dir<commit_msg>Crash if trying to create a file that already exists<commit_after>#include "CopyDir.h"
#include "CopyFile.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

#include "messmer/fspp/fuse/FuseErrnoException.h"
#include "CopyDevice.h"
#include "CopyOpenFile.h"

//TODO Get rid of this in favor of exception hierarchy
using fspp::fuse::CHECK_RETVAL;

namespace bf = boost::filesystem;

using std::unique_ptr;
using std::make_unique;
using std::string;
using std::vector;

namespace copyfs {

CopyDir::CopyDir(CopyDevice *device, const bf::path &path)
  :CopyNode(device, path) {
  assert(bf::is_directory(base_path()));
}

CopyDir::~CopyDir() {
}

unique_ptr<fspp::OpenFile> CopyDir::createAndOpenFile(const string &name, mode_t mode) {
  auto file_path = base_path() / name;
  if (bf::exists(file_path)) {
	throw fspp::fuse::FuseErrnoException(EEXIST);
  }
  //Create file
  int fd = ::creat(file_path.c_str(), mode);
  CHECK_RETVAL(fd);
  //TODO Don't close and reopen, that's inperformant
  ::close(fd);
  return make_unique<CopyOpenFile>(device(), path() / name, O_RDWR | O_TRUNC);
}

void CopyDir::createDir(const string &name, mode_t mode) {
  auto dir_path = base_path() / name;
  //Create dir
{'fraction_non_alphanumeric': 0.14980793854033292, 'fraction_numerical': 0.0, 'mean_word_length': 5.602816901408451, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2681768', 'n_tokens_mistral': 868, 'n_tokens_neox': 856, 'n_words': 202}