2015-06-23 22:24:55 -04:00
|
|
|
/*
|
2026-02-23 13:22:21 -06:00
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2016-01-14 16:50:22 -05: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.
|
2015-06-23 22:24:55 -04:00
|
|
|
*/
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "policy_ff.hpp"
|
|
|
|
|
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2018-10-13 23:48:30 -04:00
|
|
|
#include "fs_exists.hpp"
|
|
|
|
|
#include "fs_info.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "policies.hpp"
|
2015-06-23 22:24:55 -04:00
|
|
|
#include "policy.hpp"
|
2018-10-20 23:40:02 -04:00
|
|
|
#include "policy_error.hpp"
|
2015-06-23 22:24:55 -04:00
|
|
|
|
2018-10-13 23:48:30 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
2015-06-23 22:24:55 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_create(const Branches::Ptr &ibranches_,
|
|
|
|
|
std::vector<Branch*> &obranches_)
|
2015-06-30 23:35:28 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
|
|
|
|
int error;
|
|
|
|
|
fs::info_t info;
|
|
|
|
|
|
|
|
|
|
error = ENOENT;
|
|
|
|
|
for(auto &branch : *ibranches_)
|
|
|
|
|
{
|
|
|
|
|
if(branch.ro_or_nc())
|
|
|
|
|
error_and_continue(error,EROFS);
|
|
|
|
|
rv = fs::info(branch.path,&info);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
error_and_continue(error,ENOENT);
|
|
|
|
|
if(info.readonly)
|
|
|
|
|
error_and_continue(error,EROFS);
|
|
|
|
|
if(info.spaceavail < branch.minfreespace())
|
|
|
|
|
error_and_continue(error,ENOSPC);
|
|
|
|
|
|
|
|
|
|
obranches_.emplace_back(&branch);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -error;
|
2020-12-19 15:06:08 -05:00
|
|
|
}
|
2020-08-20 18:47:04 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
int
|
2025-05-17 16:35:18 -05:00
|
|
|
Policy::FF::Action::operator()(const Branches::Ptr &branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*> &paths_) const
|
2020-12-19 15:06:08 -05:00
|
|
|
{
|
|
|
|
|
return Policies::Action::epff(branches_,fusepath_,paths_);
|
2015-07-21 14:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-06 12:52:55 -05:00
|
|
|
int
|
2025-05-17 16:35:18 -05:00
|
|
|
Policy::FF::Create::operator()(const Branches::Ptr &branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*> &paths_) const
|
2015-06-23 22:24:55 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
return ::_create(branches_,paths_);
|
2020-12-19 15:06:08 -05:00
|
|
|
}
|
2015-07-21 14:19:17 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
int
|
2025-05-17 16:35:18 -05:00
|
|
|
Policy::FF::Search::operator()(const Branches::Ptr &branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*> &output_) const
|
2020-12-19 15:06:08 -05:00
|
|
|
{
|
2025-05-17 16:35:18 -05:00
|
|
|
for(auto &branch : *branches_)
|
|
|
|
|
{
|
|
|
|
|
if(!fs::exists(branch.path,fusepath_))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
output_.emplace_back(&branch);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
return -ENOENT;
|
2015-06-23 22:24:55 -04:00
|
|
|
}
|