2018-10-20 23:40:02 -04:00
|
|
|
/*
|
|
|
|
|
ISC License
|
|
|
|
|
|
2026-02-23 13:22:21 -06:00
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2018-10-20 23:40:02 -04:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "branch.hpp"
|
2020-08-20 18:47:04 -04:00
|
|
|
#include "num.hpp"
|
2018-10-20 23:40:02 -04:00
|
|
|
|
2025-05-17 16:35:18 -05:00
|
|
|
Branch::Branch()
|
2026-03-16 20:02:56 -05:00
|
|
|
: mode(Branch::Mode::RW)
|
2025-05-17 16:35:18 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Branch::Branch(const Branch &branch_)
|
|
|
|
|
: _minfreespace(branch_._minfreespace),
|
|
|
|
|
mode(branch_.mode),
|
|
|
|
|
path(branch_.path)
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-10-20 23:40:02 -04:00
|
|
|
|
2025-05-17 16:35:18 -05:00
|
|
|
Branch::Branch(const u64 &default_minfreespace_)
|
|
|
|
|
: _minfreespace(&default_minfreespace_)
|
2018-11-02 10:23:56 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-20 18:47:04 -04:00
|
|
|
std::string
|
|
|
|
|
Branch::to_string(void) const
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
std::string rv;
|
2018-10-20 23:40:02 -04:00
|
|
|
|
2020-08-20 18:47:04 -04:00
|
|
|
rv = path;
|
|
|
|
|
rv += '=';
|
|
|
|
|
switch(mode)
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
default:
|
|
|
|
|
case Branch::Mode::RW:
|
|
|
|
|
rv += "RW";
|
|
|
|
|
break;
|
|
|
|
|
case Branch::Mode::RO:
|
|
|
|
|
rv += "RO";
|
|
|
|
|
break;
|
|
|
|
|
case Branch::Mode::NC:
|
|
|
|
|
rv += "NC";
|
|
|
|
|
break;
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-17 16:35:18 -05:00
|
|
|
if(std::holds_alternative<u64>(_minfreespace))
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
rv += ',';
|
2025-05-17 16:35:18 -05:00
|
|
|
rv += num::humanize(std::get<u64>(_minfreespace));
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
2020-08-20 18:47:04 -04:00
|
|
|
|
|
|
|
|
return rv;
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2025-05-17 16:35:18 -05:00
|
|
|
Branch::set_minfreespace(const u64 minfreespace_)
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
_minfreespace = minfreespace_;
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-17 16:35:18 -05:00
|
|
|
u64
|
2020-08-20 18:47:04 -04:00
|
|
|
Branch::minfreespace(void) const
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2025-05-17 16:35:18 -05:00
|
|
|
if(std::holds_alternative<const u64*>(_minfreespace))
|
|
|
|
|
return *std::get<const u64*>(_minfreespace);
|
|
|
|
|
return std::get<u64>(_minfreespace);
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 18:47:04 -04:00
|
|
|
bool
|
|
|
|
|
Branch::ro(void) const
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
return (mode == Branch::Mode::RO);
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 18:47:04 -04:00
|
|
|
bool
|
|
|
|
|
Branch::nc(void) const
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
return (mode == Branch::Mode::NC);
|
2018-10-20 23:40:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 18:47:04 -04:00
|
|
|
bool
|
|
|
|
|
Branch::ro_or_nc(void) const
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
2020-08-20 18:47:04 -04:00
|
|
|
return ((mode == Branch::Mode::RO) ||
|
|
|
|
|
(mode == Branch::Mode::NC));
|
|
|
|
|
}
|