mergerfs/src/branch2.cpp

40 lines
711 B
C++
Raw Normal View History

2024-01-24 21:49:02 -06:00
#include "branch2.hpp"
2024-01-25 22:39:56 -06:00
2024-01-31 21:17:45 -06:00
#include <iostream>
2024-01-31 21:38:11 -06:00
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
2024-01-31 21:43:46 -06:00
#include <unistd.h>
2024-01-31 21:38:11 -06:00
2024-01-25 22:39:56 -06:00
2024-01-29 00:00:38 -06:00
Branch2::Branch2()
2024-01-31 21:57:36 -06:00
: enabled(false),
mode(Mode::RW),
min_free_space(0),
fd(-1),
path()
2024-01-29 00:00:38 -06:00
{
}
2024-01-25 22:39:56 -06:00
Branch2::Branch2(toml::value const &v_)
2024-01-29 00:02:15 -06:00
: mode(Mode::RW)
2024-01-25 22:39:56 -06:00
{
2024-01-29 00:07:09 -06:00
enabled = v_.at("enabled").as_boolean();
2024-01-31 21:20:34 -06:00
mode = Mode::_from_string(toml::find<std::string>(v_,"mode").c_str());
2024-01-29 00:07:09 -06:00
min_free_space = 0;
2024-01-29 00:07:45 -06:00
path = toml::find<std::string>(v_,"path");
2024-01-31 21:38:11 -06:00
2024-01-31 21:38:38 -06:00
int const flags = O_DIRECTORY | O_PATH | O_NOATIME;
2024-01-31 21:38:19 -06:00
fd = openat(AT_FDCWD,path.string().c_str(),flags);
2024-01-31 22:04:20 -06:00
if(fd < 0)
enabled = false;
2024-01-25 22:39:56 -06:00
}
2024-01-31 21:43:19 -06:00
Branch2::~Branch2()
{
2024-01-31 21:43:32 -06:00
if(fd >= 0)
close(fd);
2024-01-31 21:43:19 -06:00
}