mergerfs/src/branch.hpp

81 lines
1.7 KiB
C++
Raw Normal View History

/*
ISC License
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
2022-05-20 00:04:28 -04:00
#include "fs_path.hpp"
2021-03-28 12:34:30 -04:00
2022-05-20 00:04:28 -04:00
#include "toml.hpp"
#include <cstdint>
#include <string>
#include <vector>
2022-05-20 00:04:28 -04:00
class Branch
2021-03-28 12:34:30 -04:00
{
public:
enum class Mode
{
INVALID,
RO,
RW,
NC
};
static Mode str2mode(const std::string &);
public:
2022-05-20 00:04:28 -04:00
Branch(const toml::value &toml,
const Branch::Mode default_mode,
const uint64_t default_minfreespace);
2021-03-28 12:34:30 -04:00
public:
bool ro(void) const;
bool nc(void) const;
bool ro_or_nc(void) const;
public:
2022-05-20 00:04:28 -04:00
gfs::path path;
Mode mode;
uint64_t minfreespace;
2021-03-28 12:34:30 -04:00
};
namespace toml
{
template<>
2022-05-20 00:04:28 -04:00
struct from<Branch::Mode>
2021-03-28 12:34:30 -04:00
{
static
2022-05-20 00:04:28 -04:00
Branch::Mode
2021-03-28 12:34:30 -04:00
from_toml(const toml::value &v_)
{
std::string str = v_.as_string();
if(str == "RW")
2022-05-20 00:04:28 -04:00
return Branch::Mode::RW;
2021-03-28 12:34:30 -04:00
if(str == "RO")
2022-05-20 00:04:28 -04:00
return Branch::Mode::RO;
2021-03-28 12:34:30 -04:00
if(str == "NC")
2022-05-20 00:04:28 -04:00
return Branch::Mode::NC;
2021-03-28 12:34:30 -04:00
2022-05-20 00:04:28 -04:00
return Branch::Mode::RW;
2021-03-28 12:34:30 -04:00
}
};
}