mergerfs/src/error.hpp
Antonio SJ Musumeci b3b8e793f9 Change getattr and statx to bespoke policies
* Provides: slight improvement in performance as it no longer will
need to find and then act on the files.
* It doesn't make sense to support all original policy types. Most
people used 'newest' or 'ff' and 'combine' is a better default which
has same runtime as 'newest' but with better output.
2025-12-27 22:14:56 -06:00

48 lines
849 B
C++

#pragma once
#include "errno.hpp"
#include <optional>
struct Err
{
private:
std::optional<int> _err;
public:
Err()
{
}
operator int() const
{
return (_err.has_value() ? _err.value() : 0);
}
// A rough heuristic for prioritizing errors. Success always
// overrides failures. ENOENT is lowest errno priority, then EROFS
// (which can be set due to branch mode = RO) then any other error.
Err&
operator=(int new_err_)
{
if(!_err.has_value())
_err = ((new_err_ >= 0) ? 0 : new_err_);
else if(new_err_ >= 0)
_err = 0;
else if(_err == -ENOENT)
_err = new_err_;
else if((_err == -EROFS) && (new_err_ != -ENOENT))
_err = new_err_;
return *this;
}
bool
operator==(int other_)
{
if(_err.has_value())
return (_err.value() == other_);
return false;
}
};