mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Move everything to negative errno return types (#1499)
This commit is contained in:
parent
2b500f194a
commit
e8cd74cab0
177 changed files with 5952 additions and 5843 deletions
|
|
@ -14,6 +14,8 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "policy_eplus.hpp"
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
|
|
@ -29,126 +31,123 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
namespace eplus
|
||||
static
|
||||
int
|
||||
_create(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
static
|
||||
int
|
||||
create(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
Branch *obranch;
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
Branch *obranch;
|
||||
|
||||
obranch = nullptr;
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(branch.ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
rv = fs::info(branch.path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < branch.minfreespace())
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
obranch = nullptr;
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(branch.ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
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);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
eplus = info.spaceused;
|
||||
obranch = &branch;
|
||||
}
|
||||
eplus = info.spaceused;
|
||||
obranch = &branch;
|
||||
}
|
||||
|
||||
if(obranch == nullptr)
|
||||
return (errno=error,-1);
|
||||
if(obranch == nullptr)
|
||||
return -error;
|
||||
|
||||
paths_.emplace_back(obranch);
|
||||
paths_.emplace_back(obranch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
action(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
Branch *obranch;
|
||||
static
|
||||
int
|
||||
_action(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
Branch *obranch;
|
||||
|
||||
obranch = nullptr;
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(branch.ro())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
rv = fs::info(branch.path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
obranch = nullptr;
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(branch.ro())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
rv = fs::info(branch.path,&info);
|
||||
if(rv < 0)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
eplus = info.spaceused;
|
||||
obranch = &branch;
|
||||
}
|
||||
eplus = info.spaceused;
|
||||
obranch = &branch;
|
||||
}
|
||||
|
||||
if(obranch == nullptr)
|
||||
return (errno=error,-1);
|
||||
if(obranch == nullptr)
|
||||
return -error;
|
||||
|
||||
paths_.emplace_back(obranch);
|
||||
paths_.emplace_back(obranch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
search(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int rv;
|
||||
uint64_t eplus;
|
||||
uint64_t spaceused;
|
||||
Branch *obranch;
|
||||
static
|
||||
int
|
||||
_search(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int rv;
|
||||
uint64_t eplus;
|
||||
uint64_t spaceused;
|
||||
Branch *obranch;
|
||||
|
||||
obranch = nullptr;
|
||||
eplus = 0;
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
continue;
|
||||
rv = fs::statvfs_cache_spaceused(branch.path,&spaceused);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
if(spaceused >= eplus)
|
||||
continue;
|
||||
obranch = nullptr;
|
||||
eplus = 0;
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
continue;
|
||||
rv = fs::statvfs_cache_spaceused(branch.path,&spaceused);
|
||||
if(rv < 0)
|
||||
continue;
|
||||
if(spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
eplus = spaceused;
|
||||
obranch = &branch;
|
||||
}
|
||||
eplus = spaceused;
|
||||
obranch = &branch;
|
||||
}
|
||||
|
||||
if(obranch == nullptr)
|
||||
return (errno=ENOENT,-1);
|
||||
if(obranch == nullptr)
|
||||
return -ENOENT;
|
||||
|
||||
paths_.emplace_back(obranch);
|
||||
paths_.emplace_back(obranch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -156,7 +155,7 @@ Policy::EPLUS::Action::operator()(const Branches::Ptr &branches_,
|
|||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_) const
|
||||
{
|
||||
return ::eplus::action(branches_,fusepath_,paths_);
|
||||
return ::_action(branches_,fusepath_,paths_);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -164,7 +163,7 @@ Policy::EPLUS::Create::operator()(const Branches::Ptr &branches_,
|
|||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_) const
|
||||
{
|
||||
return ::eplus::create(branches_,fusepath_,paths_);
|
||||
return ::_create(branches_,fusepath_,paths_);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -172,5 +171,5 @@ Policy::EPLUS::Search::operator()(const Branches::Ptr &branches_,
|
|||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_) const
|
||||
{
|
||||
return ::eplus::search(branches_,fusepath_,paths_);
|
||||
return ::_search(branches_,fusepath_,paths_);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue