mergerfs/src/branches2.cpp

60 lines
980 B
C++
Raw Normal View History

2024-01-26 00:41:09 -06:00
#include "branches2.hpp"
2024-02-04 22:24:35 -06:00
#include "fs_clonepath.hpp"
2024-01-28 21:34:09 -06:00
#include "fmt/core.h"
2024-01-28 21:33:28 -06:00
2024-01-26 00:41:09 -06:00
#include <iostream>
2024-02-04 22:24:23 -06:00
#include <errno.h>
2024-01-26 00:41:09 -06:00
Branches2::Branches2()
{
}
Branches2::Branches2(toml::value const &v_)
{
2024-01-27 00:49:38 -06:00
auto const &tiers = toml::find(v_,"tier");
2024-01-26 00:41:09 -06:00
2024-01-27 00:49:48 -06:00
for(auto const &tier : tiers.as_array())
2024-01-26 00:41:09 -06:00
{
2024-01-28 22:44:03 -06:00
_branches.emplace_back(tier);
2024-01-26 00:41:09 -06:00
}
}
2024-02-04 22:20:26 -06:00
2024-02-07 21:06:03 -06:00
void
2024-02-07 21:06:21 -06:00
Branches2::copy_enabled_rw(Branches2 &b_)
2024-02-07 21:06:03 -06:00
{
2024-02-07 22:25:21 -06:00
_branches.resize(b_._branches.size());
2024-02-07 21:06:03 -06:00
for(auto const &bt : _branches)
{
2024-02-07 22:25:21 -06:00
BranchTier newbt;
2024-02-07 21:06:03 -06:00
2024-02-07 22:25:31 -06:00
bt.copy_enabled_rw(newbt);
2024-02-07 21:06:03 -06:00
}
}
2024-02-04 22:20:26 -06:00
int
Branches2::clonepath(ghc::filesystem::path basepath_,
ghc::filesystem::path relpath_)
{
2024-02-04 22:23:35 -06:00
int rv;
2024-02-07 20:43:42 -06:00
2024-02-04 22:23:35 -06:00
for(auto const &tier : _branches)
{
for(auto const &branch : tier)
{
if(branch.path == basepath_)
continue;
rv = fs::clonepath(branch.path,basepath_,relpath_);
2024-02-04 22:23:52 -06:00
if(rv < 0)
continue;
return 0;
2024-02-04 22:23:35 -06:00
}
}
2024-02-04 22:20:26 -06:00
2024-02-04 22:24:05 -06:00
errno = ENOENT;
return -1;
2024-02-04 22:20:26 -06:00
}