2016-08-01 15:51:28 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016, 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.
|
|
|
|
*/
|
|
|
|
|
2018-10-13 23:48:30 -04:00
|
|
|
#include "errno.hpp"
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "policies.hpp"
|
2018-10-13 23:48:30 -04:00
|
|
|
#include "policy.hpp"
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "policy_eprand.hpp"
|
2018-10-13 23:48:30 -04:00
|
|
|
|
2016-09-14 08:36:06 -04:00
|
|
|
#include <algorithm>
|
2016-08-01 15:51:28 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
int
|
|
|
|
Policy::EPRand::Action::operator()(const Branches::CPtr &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
StrVec *paths_) const
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = Policies::Action::epall(branches_,fusepath_,paths_);
|
|
|
|
if(rv == 0)
|
|
|
|
{
|
|
|
|
std::random_shuffle(paths_->begin(),paths_->end());
|
|
|
|
paths_->resize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Policy::EPRand::Create::operator()(const Branches::CPtr &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
StrVec *paths_) const
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = Policies::Create::epall(branches_,fusepath_,paths_);
|
|
|
|
if(rv == 0)
|
|
|
|
{
|
|
|
|
std::random_shuffle(paths_->begin(),paths_->end());
|
|
|
|
paths_->resize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2016-08-01 15:51:28 -04:00
|
|
|
|
2019-01-06 12:52:55 -05:00
|
|
|
int
|
2020-12-19 15:06:08 -05:00
|
|
|
Policy::EPRand::Search::operator()(const Branches::CPtr &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
StrVec *paths_) const
|
2016-08-01 15:51:28 -04:00
|
|
|
{
|
2019-01-06 12:52:55 -05:00
|
|
|
int rv;
|
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
rv = Policies::Search::epall(branches_,fusepath_,paths_);
|
2019-01-06 12:52:55 -05:00
|
|
|
if(rv == 0)
|
2019-09-07 17:23:48 -04:00
|
|
|
{
|
2019-09-24 10:27:46 -04:00
|
|
|
std::random_shuffle(paths_->begin(),paths_->end());
|
|
|
|
paths_->resize(1);
|
2019-09-07 17:23:48 -04:00
|
|
|
}
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
return rv;
|
2016-08-01 15:51:28 -04:00
|
|
|
}
|