mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-22 16:06:27 -05:00
Misc changes (#1513)
* Start moving to string_view where possible * Rework readdir object to use atomic load/store
This commit is contained in:
parent
2101ef5bcc
commit
6ac7f389c5
61 changed files with 841 additions and 745 deletions
|
|
@ -38,7 +38,7 @@ Branch::Branch(const u64 &default_minfreespace_)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Branch::from_string(const std::string &str_)
|
Branch::from_string(const std::string_view str_)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public:
|
||||||
bool ro_or_nc(void) const;
|
bool ro_or_nc(void) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &str) final;
|
int from_string(const std::string_view str) final;
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,9 @@ namespace l
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
split(const std::string &s_,
|
split(const std::string_view s_,
|
||||||
std::string *instr_,
|
std::string *instr_,
|
||||||
std::string *values_)
|
std::string *values_)
|
||||||
{
|
{
|
||||||
u64 offset;
|
u64 offset;
|
||||||
|
|
||||||
|
|
@ -222,8 +222,8 @@ namespace l
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
set(const std::string &str_,
|
set(const std::string_view str_,
|
||||||
Branches::Impl *branches_)
|
Branches::Impl *branches_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
StrVec paths;
|
StrVec paths;
|
||||||
|
|
@ -244,8 +244,8 @@ namespace l
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
add_begin(const std::string &str_,
|
add_begin(const std::string_view str_,
|
||||||
Branches::Impl *branches_)
|
Branches::Impl *branches_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
std::vector<std::string> paths;
|
std::vector<std::string> paths;
|
||||||
|
|
@ -268,8 +268,8 @@ namespace l
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
add_end(const std::string &str_,
|
add_end(const std::string_view str_,
|
||||||
Branches::Impl *branches_)
|
Branches::Impl *branches_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
StrVec paths;
|
StrVec paths;
|
||||||
|
|
@ -310,8 +310,8 @@ namespace l
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
erase_fnmatch(const std::string &str_,
|
erase_fnmatch(const std::string_view str_,
|
||||||
Branches::Impl *branches_)
|
Branches::Impl *branches_)
|
||||||
{
|
{
|
||||||
StrVec patterns;
|
StrVec patterns;
|
||||||
|
|
||||||
|
|
@ -336,7 +336,7 @@ namespace l
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Branches::Impl::from_string(const std::string &s_)
|
Branches::Impl::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
std::string instr;
|
std::string instr;
|
||||||
std::string values;
|
std::string values;
|
||||||
|
|
@ -403,7 +403,7 @@ Branches::Impl::to_paths() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Branches::from_string(const std::string &str_)
|
Branches::from_string(const std::string_view str_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
Branches::Ptr impl;
|
Branches::Ptr impl;
|
||||||
|
|
@ -462,7 +462,7 @@ SrcMounts::SrcMounts(Branches &b_)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SrcMounts::from_string(const std::string &s_)
|
SrcMounts::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
// return _branches.from_string(s_);
|
// return _branches.from_string(s_);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ public:
|
||||||
Impl(const u64 &default_minfreespace);
|
Impl(const u64 &default_minfreespace);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &str) final;
|
int from_string(const std::string_view str) final;
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -73,13 +73,20 @@ public:
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &str) final;
|
int from_string(const std::string_view str) final;
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
operator Ptr() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
|
operator Ptr() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
|
||||||
Ptr operator->() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
|
Ptr operator->() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
Impl::iterator begin() { return _impl->begin(); }
|
||||||
|
Impl::iterator end() { return _impl->end(); }
|
||||||
|
Impl::const_iterator begin() const { return _impl->begin(); }
|
||||||
|
Impl::const_iterator end() const { return _impl->end(); }
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void find_and_set_mode_ro();
|
void find_and_set_mode_ro();
|
||||||
};
|
};
|
||||||
|
|
@ -90,7 +97,7 @@ public:
|
||||||
SrcMounts(Branches &b);
|
SrcMounts(Branches &b);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &str) final;
|
int from_string(const std::string_view str) final;
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int
|
int
|
||||||
Category::Base::from_string(const std::string &s_)
|
Category::Base::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Category
|
||||||
class Base : public ToFromString
|
class Base : public ToFromString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &s) final;
|
int from_string(const std::string_view s) final;
|
||||||
std::string to_string() const final;
|
std::string to_string() const final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@
|
||||||
|
|
||||||
typedef ToFromWrapper<bool> ConfigBOOL;
|
typedef ToFromWrapper<bool> ConfigBOOL;
|
||||||
typedef ToFromWrapper<uint64_t> ConfigUINT64;
|
typedef ToFromWrapper<uint64_t> ConfigUINT64;
|
||||||
|
typedef ToFromWrapper<int64_t> ConfigS64;
|
||||||
typedef ToFromWrapper<int> ConfigINT;
|
typedef ToFromWrapper<int> ConfigINT;
|
||||||
typedef ToFromWrapper<std::string> ConfigSTR;
|
typedef ToFromWrapper<std::string> ConfigSTR;
|
||||||
typedef ToFromWrapper<std::filesystem::path> ConfigPath;
|
typedef ToFromWrapper<std::filesystem::path> ConfigPath;
|
||||||
|
|
@ -161,7 +162,7 @@ public:
|
||||||
StatFS statfs;
|
StatFS statfs;
|
||||||
StatFSIgnore statfs_ignore;
|
StatFSIgnore statfs_ignore;
|
||||||
ConfigBOOL symlinkify;
|
ConfigBOOL symlinkify;
|
||||||
ConfigUINT64 symlinkify_timeout;
|
ConfigS64 symlinkify_timeout;
|
||||||
ConfigINT fuse_read_thread_count;
|
ConfigINT fuse_read_thread_count;
|
||||||
ConfigINT fuse_process_thread_count;
|
ConfigINT fuse_process_thread_count;
|
||||||
ConfigINT fuse_process_thread_queue_depth;
|
ConfigINT fuse_process_thread_queue_depth;
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ CacheFiles::to_string() const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
CacheFiles::from_string(const std::string &s_)
|
CacheFiles::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "libfuse")
|
if(s_ == "libfuse")
|
||||||
_data = CacheFiles::ENUM::LIBFUSE;
|
_data = CacheFiles::ENUM::LIBFUSE;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ FlushOnClose::to_string() const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
FlushOnClose::from_string(const std::string &s_)
|
FlushOnClose::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "never")
|
if(s_ == "never")
|
||||||
_data = FlushOnClose::ENUM::NEVER;
|
_data = FlushOnClose::ENUM::NEVER;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ FollowSymlinks::to_string(void) const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
FollowSymlinks::from_string(const std::string &s_)
|
FollowSymlinks::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "never")
|
if(s_ == "never")
|
||||||
_data = FollowSymlinks::ENUM::NEVER;
|
_data = FollowSymlinks::ENUM::NEVER;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ GIDCacheExpireTimeout::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
GIDCacheExpireTimeout::from_string(const std::string &s_)
|
GIDCacheExpireTimeout::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ GIDCacheRemoveTimeout::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
GIDCacheRemoveTimeout::from_string(const std::string &s_)
|
GIDCacheRemoveTimeout::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GIDCacheRemoveTimeout : public ToFromString
|
class GIDCacheRemoveTimeout : public ToFromString
|
||||||
|
|
@ -21,5 +21,5 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ InodeCalc::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
InodeCalc::from_string(const std::string &s_)
|
InodeCalc::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
return fs::inode::set_algo(s_);
|
return fs::inode::set_algo(s_);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,5 +28,5 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ LinkEXDEV::to_string(void) const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
LinkEXDEV::from_string(const std::string &s_)
|
LinkEXDEV::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "passthrough")
|
if(s_ == "passthrough")
|
||||||
_data = LinkEXDEV::ENUM::PASSTHROUGH;
|
_data = LinkEXDEV::ENUM::PASSTHROUGH;
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ LogMetrics::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
LogMetrics::from_string(const std::string &s_)
|
LogMetrics::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
bool val;
|
bool val;
|
||||||
|
|
|
||||||
|
|
@ -27,5 +27,5 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
MoveOnENOSPC::from_string(const std::string &s_)
|
MoveOnENOSPC::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &s) final;
|
int from_string(const std::string_view s) final;
|
||||||
std::string to_string() const final;
|
std::string to_string() const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
NFSOpenHack::from_string(const std::string &s_)
|
NFSOpenHack::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "off")
|
if(s_ == "off")
|
||||||
_data = NFSOpenHack::ENUM::OFF;
|
_data = NFSOpenHack::ENUM::OFF;
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ ConfigPageSize::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ConfigPageSize::from_string(const std::string &s_)
|
ConfigPageSize::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
uint64_t v;
|
uint64_t v;
|
||||||
uint64_t pagesize;
|
uint64_t pagesize;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConfigPageSize&
|
ConfigPageSize&
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ Passthrough::to_string() const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
Passthrough::from_string(const std::string &s_)
|
Passthrough::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "off")
|
if(s_ == "off")
|
||||||
_data = Passthrough::ENUM::OFF;
|
_data = Passthrough::ENUM::OFF;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
from_string(const std::string &) final
|
from_string(const std::string_view) final
|
||||||
{
|
{
|
||||||
return -EROFS;
|
return -EROFS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ RenameEXDEV::to_string(void) const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
RenameEXDEV::from_string(const std::string &s_)
|
RenameEXDEV::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "passthrough")
|
if(s_ == "passthrough")
|
||||||
_data = RenameEXDEV::ENUM::PASSTHROUGH;
|
_data = RenameEXDEV::ENUM::PASSTHROUGH;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ ConfigSet::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ConfigSet::from_string(const std::string &str_)
|
ConfigSet::from_string(const std::string_view str_)
|
||||||
{
|
{
|
||||||
this->clear();
|
this->clear();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,5 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string(void) const final;
|
std::string to_string(void) const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ StatFS::to_string() const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
StatFS::from_string(const std::string &s_)
|
StatFS::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "base")
|
if(s_ == "base")
|
||||||
_data = StatFS::ENUM::BASE;
|
_data = StatFS::ENUM::BASE;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ StatFSIgnore::to_string() const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
StatFSIgnore::from_string(const std::string &s_)
|
StatFSIgnore::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "none")
|
if(s_ == "none")
|
||||||
_data = StatFSIgnore::ENUM::NONE;
|
_data = StatFSIgnore::ENUM::NONE;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ XAttr::to_string() const
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int
|
int
|
||||||
XAttr::from_string(const std::string &s_)
|
XAttr::from_string(const std::string_view s_)
|
||||||
{
|
{
|
||||||
if(s_ == "passthrough")
|
if(s_ == "passthrough")
|
||||||
_data = XAttr::ENUM::PASSTHROUGH;
|
_data = XAttr::ENUM::PASSTHROUGH;
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string() const final;
|
std::string to_string() const final;
|
||||||
int from_string(const std::string &) final;
|
int from_string(const std::string_view) final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int to_int() const
|
int to_int() const
|
||||||
|
|
|
||||||
|
|
@ -21,119 +21,175 @@
|
||||||
#include "ef.hpp"
|
#include "ef.hpp"
|
||||||
#include "errno.hpp"
|
#include "errno.hpp"
|
||||||
|
|
||||||
|
#include <charconv>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
namespace str
|
int
|
||||||
|
str::from(const std::string_view value_,
|
||||||
|
bool *bool_)
|
||||||
{
|
{
|
||||||
int
|
if((value_ == "true") ||
|
||||||
from(const std::string &value_,
|
(value_ == "1") ||
|
||||||
bool *bool_)
|
(value_ == "on") ||
|
||||||
{
|
(value_ == "yes"))
|
||||||
if((value_ == "true") ||
|
*bool_ = true;
|
||||||
(value_ == "1") ||
|
ef((value_ == "false") ||
|
||||||
(value_ == "on") ||
|
(value_ == "0") ||
|
||||||
(value_ == "yes"))
|
(value_ == "off") ||
|
||||||
*bool_ = true;
|
(value_ == "no"))
|
||||||
ef((value_ == "false") ||
|
*bool_ = false;
|
||||||
(value_ == "0") ||
|
else
|
||||||
(value_ == "off") ||
|
|
||||||
(value_ == "no"))
|
|
||||||
*bool_ = false;
|
|
||||||
else
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
from(const std::string &value_,
|
|
||||||
int *int_)
|
|
||||||
{
|
|
||||||
int tmp;
|
|
||||||
char *endptr;
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
tmp = ::strtol(value_.c_str(),&endptr,10);
|
|
||||||
if(errno != 0)
|
|
||||||
return -EINVAL;
|
|
||||||
if(endptr == value_.c_str())
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
*int_ = tmp;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
from(const std::string &value_,
|
|
||||||
uint64_t *uint64_)
|
|
||||||
{
|
|
||||||
char *endptr;
|
|
||||||
uint64_t tmp;
|
|
||||||
|
|
||||||
tmp = ::strtoll(value_.c_str(),&endptr,10);
|
|
||||||
switch(*endptr)
|
|
||||||
{
|
|
||||||
case 'b':
|
|
||||||
case 'B':
|
|
||||||
tmp *= 1ULL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'k':
|
|
||||||
case 'K':
|
|
||||||
tmp *= 1024ULL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'm':
|
|
||||||
case 'M':
|
|
||||||
tmp *= (1024ULL * 1024ULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'g':
|
|
||||||
case 'G':
|
|
||||||
tmp *= (1024ULL * 1024ULL * 1024ULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 't':
|
|
||||||
case 'T':
|
|
||||||
tmp *= (1024ULL * 1024ULL * 1024ULL * 1024ULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\0':
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*uint64_ = tmp;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
from(const std::string &value_,
|
|
||||||
std::string *str_)
|
|
||||||
{
|
|
||||||
*str_ = value_;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
from(const std::string &value_,
|
|
||||||
const std::string *key_)
|
|
||||||
{
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
int
|
return 0;
|
||||||
from(const std::string &value_,
|
}
|
||||||
fs::Path *path_)
|
|
||||||
{
|
int
|
||||||
*path_ = value_;
|
str::from(const std::string_view val_,
|
||||||
|
int *rv_)
|
||||||
return 0;
|
{
|
||||||
}
|
int tmp;
|
||||||
|
const int base = 10;
|
||||||
|
|
||||||
|
auto [ptr,ec] = std::from_chars(val_.begin(),
|
||||||
|
val_.end(),
|
||||||
|
tmp,
|
||||||
|
base);
|
||||||
|
if(ec != std::errc{})
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
*rv_ = tmp;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
str::from(const std::string_view val_,
|
||||||
|
int64_t *rv_)
|
||||||
|
{
|
||||||
|
int64_t tmp;
|
||||||
|
const int base = 10;
|
||||||
|
|
||||||
|
auto [ptr,ec] = std::from_chars(val_.begin(),
|
||||||
|
val_.end(),
|
||||||
|
tmp,
|
||||||
|
base);
|
||||||
|
|
||||||
|
if(ec != std::errc{})
|
||||||
|
return -EINVAL;
|
||||||
|
*rv_ = tmp;
|
||||||
|
if(ptr == val_.end())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch(*ptr)
|
||||||
|
{
|
||||||
|
case 'b':
|
||||||
|
case 'B':
|
||||||
|
*rv_ *= 1ULL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'k':
|
||||||
|
case 'K':
|
||||||
|
*rv_ *= 1024ULL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
case 'M':
|
||||||
|
*rv_ *= (1024ULL * 1024ULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
case 'G':
|
||||||
|
*rv_ *= (1024ULL * 1024ULL * 1024ULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
case 'T':
|
||||||
|
*rv_ *= (1024ULL * 1024ULL * 1024ULL * 1024ULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
str::from(const std::string_view val_,
|
||||||
|
uint64_t *rv_)
|
||||||
|
{
|
||||||
|
uint64_t tmp;
|
||||||
|
const int base = 10;
|
||||||
|
|
||||||
|
auto [ptr,ec] = std::from_chars(val_.begin(),
|
||||||
|
val_.end(),
|
||||||
|
tmp,
|
||||||
|
base);
|
||||||
|
|
||||||
|
if(ec != std::errc{})
|
||||||
|
return -EINVAL;
|
||||||
|
*rv_ = tmp;
|
||||||
|
if(ptr == val_.end())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch(*ptr)
|
||||||
|
{
|
||||||
|
case 'b':
|
||||||
|
case 'B':
|
||||||
|
*rv_ *= 1ULL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'k':
|
||||||
|
case 'K':
|
||||||
|
*rv_ *= 1024ULL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
case 'M':
|
||||||
|
*rv_ *= (1024ULL * 1024ULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
case 'G':
|
||||||
|
*rv_ *= (1024ULL * 1024ULL * 1024ULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
case 'T':
|
||||||
|
*rv_ *= (1024ULL * 1024ULL * 1024ULL * 1024ULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
str::from(const std::string_view value_,
|
||||||
|
std::string *str_)
|
||||||
|
{
|
||||||
|
*str_ = value_;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
str::from(const std::string_view value_,
|
||||||
|
const std::string *key_)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
str::from(const std::string_view value_,
|
||||||
|
std::filesystem::path *path_)
|
||||||
|
{
|
||||||
|
*path_ = value_;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,19 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "fs_path.hpp"
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
|
||||||
namespace str
|
namespace str
|
||||||
{
|
{
|
||||||
int from(const std::string &, bool *);
|
int from(const std::string_view, bool *);
|
||||||
int from(const std::string &, int *);
|
int from(const std::string_view, int *);
|
||||||
int from(const std::string &, uint64_t *);
|
int from(const std::string_view, uint64_t *);
|
||||||
int from(const std::string &, std::string *);
|
int from(const std::string_view, int64_t *);
|
||||||
int from(const std::string &, const std::string *);
|
int from(const std::string_view, std::string *);
|
||||||
int from(const std::string &, fs::Path *);
|
int from(const std::string_view, const std::string *);
|
||||||
|
int from(const std::string_view, std::filesystem::path *);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ _hybrid_hash32(const std::string_view branch_path_,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fs::inode::set_algo(const std::string &algo_)
|
fs::inode::set_algo(const std::string_view algo_)
|
||||||
{
|
{
|
||||||
if(algo_ == "passthrough")
|
if(algo_ == "passthrough")
|
||||||
g_func = ::_passthrough;
|
g_func = ::_passthrough;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace fs
|
||||||
{
|
{
|
||||||
namespace inode
|
namespace inode
|
||||||
{
|
{
|
||||||
int set_algo(const std::string &s);
|
int set_algo(const std::string_view s);
|
||||||
std::string get_algo(void);
|
std::string get_algo(void);
|
||||||
|
|
||||||
uint64_t calc(const std::string_view basepath,
|
uint64_t calc(const std::string_view basepath,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Func::Base::Action::from_string(const std::string &policyname_)
|
Func::Base::Action::from_string(const std::string_view policyname_)
|
||||||
{
|
{
|
||||||
policy = Policies::Action::find(policyname_);
|
policy = Policies::Action::find(policyname_);
|
||||||
if(!policy)
|
if(!policy)
|
||||||
|
|
@ -36,7 +36,7 @@ Func::Base::Action::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Func::Base::Create::from_string(const std::string &policyname_)
|
Func::Base::Create::from_string(const std::string_view policyname_)
|
||||||
{
|
{
|
||||||
policy = Policies::Create::find(policyname_);
|
policy = Policies::Create::find(policyname_);
|
||||||
if(!policy)
|
if(!policy)
|
||||||
|
|
@ -52,7 +52,7 @@ Func::Base::Create::to_string(void) const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Func::Base::Search::from_string(const std::string &policyname_)
|
Func::Base::Search::from_string(const std::string_view policyname_)
|
||||||
{
|
{
|
||||||
policy = Policies::Search::find(policyname_);
|
policy = Policies::Search::find(policyname_);
|
||||||
if(!policy)
|
if(!policy)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Func
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &s) final;
|
int from_string(const std::string_view s) final;
|
||||||
std::string to_string() const final;
|
std::string to_string() const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Func
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &s) final;
|
int from_string(const std::string_view s) final;
|
||||||
std::string to_string() const final;
|
std::string to_string() const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -67,7 +67,7 @@ namespace Func
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int from_string(const std::string &s) final;
|
int from_string(const std::string_view s) final;
|
||||||
std::string to_string() const final;
|
std::string to_string() const final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -192,8 +192,6 @@ FUSE::init(fuse_conn_info *conn_)
|
||||||
procfs::init();
|
procfs::init();
|
||||||
ugid::init();
|
ugid::init();
|
||||||
|
|
||||||
cfg->readdir.initialize();
|
|
||||||
|
|
||||||
::_want_if_capable(conn_,FUSE_CAP_ASYNC_DIO);
|
::_want_if_capable(conn_,FUSE_CAP_ASYNC_DIO);
|
||||||
::_want_if_capable(conn_,FUSE_CAP_ASYNC_READ,&cfg->async_read);
|
::_want_if_capable(conn_,FUSE_CAP_ASYNC_READ,&cfg->async_read);
|
||||||
::_want_if_capable(conn_,FUSE_CAP_ATOMIC_O_TRUNC);
|
::_want_if_capable(conn_,FUSE_CAP_ATOMIC_O_TRUNC);
|
||||||
|
|
|
||||||
|
|
@ -44,56 +44,36 @@ FUSE::readdir(const fuse_file_info_t *ffi_,
|
||||||
return cfg->readdir(ffi_,buf_);
|
return cfg->readdir(ffi_,buf_);
|
||||||
}
|
}
|
||||||
|
|
||||||
FUSE::ReadDir::ReadDir(std::string const s_)
|
FUSE::ReadDir::ReadDir(const std::string_view s_)
|
||||||
: _initialized(false)
|
: _str(new std::string())
|
||||||
{
|
{
|
||||||
from_string(s_);
|
from_string(s_);
|
||||||
if(_initialized)
|
|
||||||
assert(_readdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
FUSE::ReadDir::to_string() const
|
FUSE::ReadDir::to_string() const
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lg(_mutex);
|
std::shared_ptr<std::string> str;
|
||||||
|
|
||||||
return _type;
|
str = std::atomic_load(&_str);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
return (*str);
|
||||||
FUSE::ReadDir::initialize()
|
|
||||||
{
|
|
||||||
_initialized = true;
|
|
||||||
from_string(_type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
FUSE::ReadDir::from_string(std::string const &str_)
|
FUSE::ReadDir::from_string(const std::string_view str_)
|
||||||
{
|
{
|
||||||
if(_initialized)
|
std::shared_ptr<std::string> tmp_str;
|
||||||
{
|
std::shared_ptr<FUSE::ReadDirBase> tmp_readdir;
|
||||||
std::shared_ptr<FUSE::ReadDirBase> tmp;
|
|
||||||
|
|
||||||
tmp = FUSE::ReadDirFactory::make(str_);
|
tmp_readdir = FUSE::ReadDirFactory::make(str_);
|
||||||
if(!tmp)
|
if(!tmp_readdir)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
{
|
tmp_str = std::make_shared<std::string>(str_);
|
||||||
std::lock_guard<std::mutex> lg(_mutex);
|
|
||||||
|
|
||||||
_type = str_;
|
std::atomic_store(&_str,tmp_str);
|
||||||
std::swap(_readdir,tmp);
|
std::atomic_store(&_impl,tmp_readdir);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lg(_mutex);
|
|
||||||
|
|
||||||
if(!FUSE::ReadDirFactory::valid(str_))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
_type = str_;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +93,7 @@ _handle_ENOENT(const fuse_file_info_t *ffi_,
|
||||||
|
|
||||||
de.d_ino = 0;
|
de.d_ino = 0;
|
||||||
de.d_off = 0;
|
de.d_off = 0;
|
||||||
de.d_type = DT_REG;
|
de.d_type = DT_UNKNOWN;
|
||||||
strcpy(de.d_name,"error: no valid mergerfs branch found, check config");
|
strcpy(de.d_name,"error: no valid mergerfs branch found, check config");
|
||||||
de.d_reclen = sizeof(de);
|
de.d_reclen = sizeof(de);
|
||||||
|
|
||||||
|
|
@ -134,10 +114,7 @@ FUSE::ReadDir::operator()(const fuse_file_info_t *ffi_,
|
||||||
int rv;
|
int rv;
|
||||||
std::shared_ptr<FUSE::ReadDirBase> readdir;
|
std::shared_ptr<FUSE::ReadDirBase> readdir;
|
||||||
|
|
||||||
{
|
readdir = std::atomic_load(&_impl);
|
||||||
std::lock_guard<std::mutex> lg(_mutex);
|
|
||||||
readdir = _readdir;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = (*readdir)(ffi_,buf_);
|
rv = (*readdir)(ffi_,buf_);
|
||||||
if(rv == -ENOENT)
|
if(rv == -ENOENT)
|
||||||
|
|
|
||||||
|
|
@ -25,37 +25,30 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
// The initialization behavior is not pretty but for the moment
|
|
||||||
// needed due to the daemonizing function of the libfuse library when
|
|
||||||
// not using foreground mode. The threads need to be created after the
|
|
||||||
// fork, not before.
|
|
||||||
namespace FUSE
|
namespace FUSE
|
||||||
{
|
{
|
||||||
int readdir(fuse_file_info_t const *ffi,
|
int readdir(fuse_file_info_t const *ffi,
|
||||||
fuse_dirents_t *buf);
|
fuse_dirents_t *buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace FUSE
|
||||||
|
{
|
||||||
class ReadDir : public ToFromString
|
class ReadDir : public ToFromString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ReadDir(std::string const s_);
|
ReadDir(const std::string_view s_);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string to_string() const;
|
std::string to_string() const;
|
||||||
int from_string(const std::string &);
|
int from_string(const std::string_view);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int operator()(fuse_file_info_t const *ffi,
|
int operator()(fuse_file_info_t const *ffi,
|
||||||
fuse_dirents_t *buf);
|
fuse_dirents_t *buf);
|
||||||
|
|
||||||
public:
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::mutex _mutex;
|
std::shared_ptr<std::string> _str;
|
||||||
|
std::shared_ptr<FUSE::ReadDirBase> _impl;
|
||||||
private:
|
|
||||||
bool _initialized;
|
|
||||||
std::string _type;
|
|
||||||
std::shared_ptr<FUSE::ReadDirBase> _readdir;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include "fuse.h"
|
#include "fuse.h"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
|
||||||
namespace FUSE
|
namespace FUSE
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,31 +22,46 @@
|
||||||
#include "fuse_readdir_cosr.hpp"
|
#include "fuse_readdir_cosr.hpp"
|
||||||
#include "fuse_readdir_seq.hpp"
|
#include "fuse_readdir_seq.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <set>
|
#include <regex>
|
||||||
|
|
||||||
|
|
||||||
|
// Regex:
|
||||||
|
// ^([a-z]{1,15}) -> required type
|
||||||
|
// (?::(\d+))? -> optional colon + concurrency
|
||||||
|
// (?::(\d+))? -> optional colon + max_queue_depth
|
||||||
|
// $ -> end of string
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
_read_cfg(std::string const str_,
|
_read_cfg(const std::string_view str_,
|
||||||
std::string &type_,
|
std::string &type_,
|
||||||
unsigned &concurrency_,
|
int &concurrency_,
|
||||||
unsigned &max_queue_depth_)
|
int &max_queue_depth_)
|
||||||
{
|
{
|
||||||
char type[16];
|
std::string type;
|
||||||
int concurrency;
|
int concurrency;
|
||||||
int max_queue_depth;
|
int max_queue_depth;
|
||||||
|
bool matched;
|
||||||
|
std::cmatch match;
|
||||||
|
std::regex re(R"(^([a-z]{1,15})(?::(\d+))?(?::(\d+))?$)");
|
||||||
|
|
||||||
concurrency = 0;
|
concurrency = 0;
|
||||||
max_queue_depth = 0;
|
max_queue_depth = 0;
|
||||||
std::sscanf(str_.c_str(),
|
matched = std::regex_match(str_.begin(),
|
||||||
"%15[a-z]:%d:%d",
|
str_.end(),
|
||||||
type,
|
match,
|
||||||
&concurrency,
|
re);
|
||||||
&max_queue_depth);
|
if(matched)
|
||||||
|
{
|
||||||
|
type = match[1];
|
||||||
|
if(match[2].matched)
|
||||||
|
concurrency = std::stoi(match[2]);
|
||||||
|
if(match[3].matched)
|
||||||
|
max_queue_depth = std::stoi(match[3]);
|
||||||
|
}
|
||||||
|
|
||||||
if(concurrency == 0)
|
if(concurrency == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -73,37 +88,13 @@ _read_cfg(std::string const str_,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
FUSE::ReadDirFactory::valid(const std::string str_)
|
|
||||||
{
|
|
||||||
unsigned concurrency;
|
|
||||||
unsigned max_queue_depth;
|
|
||||||
std::string type;
|
|
||||||
static const std::set<std::string> types =
|
|
||||||
{
|
|
||||||
"seq", "cosr", "cor"
|
|
||||||
};
|
|
||||||
|
|
||||||
::_read_cfg(str_,type,concurrency,max_queue_depth);
|
|
||||||
|
|
||||||
if(types.find(type) == types.end())
|
|
||||||
return false;
|
|
||||||
if(concurrency <= 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<FUSE::ReadDirBase>
|
std::shared_ptr<FUSE::ReadDirBase>
|
||||||
FUSE::ReadDirFactory::make(std::string const str_)
|
FUSE::ReadDirFactory::make(const std::string_view str_)
|
||||||
{
|
{
|
||||||
unsigned concurrency;
|
int concurrency;
|
||||||
unsigned max_queue_depth;
|
int max_queue_depth;
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
||||||
if(!valid(str_))
|
|
||||||
return {};
|
|
||||||
|
|
||||||
::_read_cfg(str_,type,concurrency,max_queue_depth);
|
::_read_cfg(str_,type,concurrency,max_queue_depth);
|
||||||
|
|
||||||
if(type == "seq")
|
if(type == "seq")
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ namespace FUSE
|
||||||
class ReadDirFactory
|
class ReadDirFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool valid(std::string str);
|
static std::shared_ptr<ReadDirBase> make(const std::string_view str);
|
||||||
static std::shared_ptr<ReadDirBase> make(std::string const str);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,11 @@ FUSE::statx(const char *fusepath_,
|
||||||
if(Config::is_ctrl_file(fusepath_))
|
if(Config::is_ctrl_file(fusepath_))
|
||||||
return ::_statx_controlfile(st_);
|
return ::_statx_controlfile(st_);
|
||||||
|
|
||||||
return ::_statx(fusepath_,flags_|AT_STATX_DONT_SYNC,mask_,st_,timeout_);
|
return ::_statx(fusepath_,
|
||||||
|
flags_|AT_STATX_DONT_SYNC,
|
||||||
|
mask_,
|
||||||
|
st_,
|
||||||
|
timeout_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -222,5 +226,9 @@ FUSE::statx_fh(const uint64_t fh_,
|
||||||
{
|
{
|
||||||
FileInfo *fi = reinterpret_cast<FileInfo*>(fh_);
|
FileInfo *fi = reinterpret_cast<FileInfo*>(fh_);
|
||||||
|
|
||||||
return ::_statx(fi->fusepath.c_str(),flags_,mask_,st_,timeout_);
|
return ::_statx(fi->fusepath.c_str(),
|
||||||
|
flags_|AT_STATX_DONT_SYNC,
|
||||||
|
mask_,
|
||||||
|
st_,
|
||||||
|
timeout_);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ namespace l
|
||||||
orig = oom::get_oom_score_adj();
|
orig = oom::get_oom_score_adj();
|
||||||
rv = oom::set_oom_score_adj(score);
|
rv = oom::set_oom_score_adj(score);
|
||||||
|
|
||||||
|
(void)rv;
|
||||||
SysLog::info("set oom_score_adj to {}, originally {}",
|
SysLog::info("set oom_score_adj to {}, originally {}",
|
||||||
score,
|
score,
|
||||||
orig);
|
orig);
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ mergerfs::api::allpaths(const std::string &input_path_,
|
||||||
if(rv < 0)
|
if(rv < 0)
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
str::split_on_null(val.data(),val.size(),&output_paths_);
|
str::split_on_null(val,&output_paths_);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
81
src/num.cpp
81
src/num.cpp
|
|
@ -24,7 +24,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#define KB (1024ULL)
|
#define KB (1024ULL)
|
||||||
#define MB (KB * 1024ULL)
|
#define MB (KB * 1024ULL)
|
||||||
|
|
@ -33,85 +33,6 @@
|
||||||
|
|
||||||
|
|
||||||
namespace num
|
namespace num
|
||||||
{
|
|
||||||
int
|
|
||||||
to_uint64_t(const std::string &str,
|
|
||||||
uint64_t &value)
|
|
||||||
{
|
|
||||||
char *endptr;
|
|
||||||
uint64_t tmp;
|
|
||||||
|
|
||||||
tmp = strtoll(str.c_str(),&endptr,10);
|
|
||||||
switch(*endptr)
|
|
||||||
{
|
|
||||||
case 'k':
|
|
||||||
case 'K':
|
|
||||||
tmp *= 1024;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'm':
|
|
||||||
case 'M':
|
|
||||||
tmp *= (1024 * 1024);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'g':
|
|
||||||
case 'G':
|
|
||||||
tmp *= (1024 * 1024 * 1024);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 't':
|
|
||||||
case 'T':
|
|
||||||
tmp *= (1024ULL * 1024 * 1024 * 1024);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\0':
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
value = tmp;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
to_double(const std::string &str_,
|
|
||||||
double *d_)
|
|
||||||
{
|
|
||||||
double tmp;
|
|
||||||
char *endptr;
|
|
||||||
|
|
||||||
tmp = strtod(str_.c_str(),&endptr);
|
|
||||||
if(*endptr != '\0')
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
*d_ = tmp;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
to_time_t(const std::string &str,
|
|
||||||
time_t &value)
|
|
||||||
{
|
|
||||||
time_t tmp;
|
|
||||||
char *endptr;
|
|
||||||
|
|
||||||
tmp = strtoll(str.c_str(),&endptr,10);
|
|
||||||
if(*endptr != '\0')
|
|
||||||
return -1;
|
|
||||||
if(tmp < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
value = tmp;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace num
|
|
||||||
{
|
{
|
||||||
std::string
|
std::string
|
||||||
humanize(const uint64_t bytes_)
|
humanize(const uint64_t bytes_)
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,6 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
namespace num
|
|
||||||
{
|
|
||||||
int to_uint64_t(const std::string &str, uint64_t *value);
|
|
||||||
int to_double(const std::string &str, double *value);
|
|
||||||
int to_time_t(const std::string &str, time_t *value);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace num
|
namespace num
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ _parse_and_process_kv_arg(Config::Write &cfg_,
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
process_opt(Config::Write &cfg_,
|
_process_opt(Config::Write &cfg_,
|
||||||
Config::ErrVec *errs_,
|
Config::ErrVec *errs_,
|
||||||
const std::string &arg_)
|
const std::string &arg_)
|
||||||
{
|
{
|
||||||
|
|
@ -220,7 +220,7 @@ process_opt(Config::Write &cfg_,
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
process_branches(Config::Write &cfg_,
|
_process_branches(Config::Write &cfg_,
|
||||||
Config::ErrVec *errs_,
|
Config::ErrVec *errs_,
|
||||||
const char *arg_)
|
const char *arg_)
|
||||||
{
|
{
|
||||||
|
|
@ -237,7 +237,7 @@ process_branches(Config::Write &cfg_,
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
process_mount(Config::Write &cfg_,
|
_process_mount(Config::Write &cfg_,
|
||||||
Config::ErrVec *errs_,
|
Config::ErrVec *errs_,
|
||||||
const char *arg_)
|
const char *arg_)
|
||||||
{
|
{
|
||||||
|
|
@ -290,10 +290,10 @@ _usage(void)
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
option_processor(void *data_,
|
_option_processor(void *data_,
|
||||||
const char *arg_,
|
const char *arg_,
|
||||||
int key_,
|
int key_,
|
||||||
fuse_args *outargs_)
|
fuse_args *outargs_)
|
||||||
{
|
{
|
||||||
Config::Write cfg;
|
Config::Write cfg;
|
||||||
Config::ErrVec *errs = (Config::ErrVec*)data_;
|
Config::ErrVec *errs = (Config::ErrVec*)data_;
|
||||||
|
|
@ -301,13 +301,13 @@ option_processor(void *data_,
|
||||||
switch(key_)
|
switch(key_)
|
||||||
{
|
{
|
||||||
case FUSE_OPT_KEY_OPT:
|
case FUSE_OPT_KEY_OPT:
|
||||||
return process_opt(cfg,errs,arg_);
|
return ::_process_opt(cfg,errs,arg_);
|
||||||
|
|
||||||
case FUSE_OPT_KEY_NONOPT:
|
case FUSE_OPT_KEY_NONOPT:
|
||||||
if(cfg->branches->empty())
|
if(cfg->branches->empty())
|
||||||
return process_branches(cfg,errs,arg_);
|
return ::_process_branches(cfg,errs,arg_);
|
||||||
else
|
else
|
||||||
return process_mount(cfg,errs,arg_);
|
return ::_process_mount(cfg,errs,arg_);
|
||||||
|
|
||||||
case MERGERFS_OPT_HELP:
|
case MERGERFS_OPT_HELP:
|
||||||
::_usage();
|
::_usage();
|
||||||
|
|
@ -367,6 +367,41 @@ _check_for_mount_loop(Config::Write &cfg_,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
_print_warnings(Config::Write &cfg_)
|
||||||
|
{
|
||||||
|
if(cfg_->passthrough != Passthrough::ENUM::OFF)
|
||||||
|
{
|
||||||
|
if(cfg_->cache_files == CacheFiles::ENUM::OFF)
|
||||||
|
{
|
||||||
|
SysLog::warning("'cache.files' can not be 'off' when using 'passthrough'."
|
||||||
|
" Setting 'cache.files=auto-full'");
|
||||||
|
cfg_->cache_files = CacheFiles::ENUM::AUTO_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cfg_->writeback_cache == true)
|
||||||
|
{
|
||||||
|
SysLog::warning("'cache.writeback' can not be enabled when using 'passthrough'."
|
||||||
|
" Setting 'cache.writeback=false'");
|
||||||
|
cfg_->writeback_cache = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cfg_->moveonenospc.enabled == true)
|
||||||
|
{
|
||||||
|
SysLog::warning("`moveonenospc` will not function when `passthrough` is enabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
_cleanup_options(Config::Write &cfg_)
|
||||||
|
{
|
||||||
|
if(!cfg_->symlinkify)
|
||||||
|
cfg_->symlinkify_timeout = -1;
|
||||||
|
}
|
||||||
|
|
||||||
namespace options
|
namespace options
|
||||||
{
|
{
|
||||||
void
|
void
|
||||||
|
|
@ -387,7 +422,7 @@ namespace options
|
||||||
fuse_opt_parse(args_,
|
fuse_opt_parse(args_,
|
||||||
errs_,
|
errs_,
|
||||||
opts,
|
opts,
|
||||||
::option_processor);
|
::_option_processor);
|
||||||
|
|
||||||
if(cfg->branches->empty())
|
if(cfg->branches->empty())
|
||||||
errs_->push_back({0,"branches not set"});
|
errs_->push_back({0,"branches not set"});
|
||||||
|
|
@ -400,6 +435,8 @@ namespace options
|
||||||
::_set_fsname(cfg,args_);
|
::_set_fsname(cfg,args_);
|
||||||
::_set_subtype(args_);
|
::_set_subtype(args_);
|
||||||
::_set_fuse_threads(cfg);
|
::_set_fuse_threads(cfg);
|
||||||
|
::_print_warnings(cfg);
|
||||||
|
::_cleanup_options(cfg);
|
||||||
|
|
||||||
cfg->finish_initializing();
|
cfg->finish_initializing();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
FUNC(rand)
|
FUNC(rand)
|
||||||
|
|
||||||
Policy::ActionImpl*
|
Policy::ActionImpl*
|
||||||
Policies::Action::find(const std::string &name_)
|
Policies::Action::find(const std::string_view name_)
|
||||||
{
|
{
|
||||||
IFERT(IFERTA);
|
IFERT(IFERTA);
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ Policies::Action::find(const std::string &name_)
|
||||||
}
|
}
|
||||||
|
|
||||||
Policy::CreateImpl*
|
Policy::CreateImpl*
|
||||||
Policies::Create::find(const std::string &name_)
|
Policies::Create::find(const std::string_view name_)
|
||||||
{
|
{
|
||||||
IFERT(IFERTC);
|
IFERT(IFERTC);
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ Policies::Create::find(const std::string &name_)
|
||||||
}
|
}
|
||||||
|
|
||||||
Policy::SearchImpl*
|
Policy::SearchImpl*
|
||||||
Policies::Search::find(const std::string &name_)
|
Policies::Search::find(const std::string_view name_)
|
||||||
{
|
{
|
||||||
IFERT(IFERTS);
|
IFERT(IFERTS);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ struct Policies
|
||||||
{
|
{
|
||||||
struct Action
|
struct Action
|
||||||
{
|
{
|
||||||
static Policy::ActionImpl *find(const std::string &name);
|
static Policy::ActionImpl *find(const std::string_view name);
|
||||||
|
|
||||||
static Policy::All::Action all;
|
static Policy::All::Action all;
|
||||||
static Policy::EPAll::Action epall;
|
static Policy::EPAll::Action epall;
|
||||||
|
|
@ -69,7 +69,7 @@ struct Policies
|
||||||
|
|
||||||
struct Create
|
struct Create
|
||||||
{
|
{
|
||||||
static Policy::CreateImpl *find(const std::string &name);
|
static Policy::CreateImpl *find(const std::string_view name);
|
||||||
|
|
||||||
static Policy::All::Create all;
|
static Policy::All::Create all;
|
||||||
static Policy::EPAll::Create epall;
|
static Policy::EPAll::Create epall;
|
||||||
|
|
@ -95,7 +95,7 @@ struct Policies
|
||||||
|
|
||||||
struct Search
|
struct Search
|
||||||
{
|
{
|
||||||
static Policy::SearchImpl *find(const std::string &name);
|
static Policy::SearchImpl *find(const std::string_view name);
|
||||||
|
|
||||||
static Policy::All::Search all;
|
static Policy::All::Search all;
|
||||||
static Policy::EPAll::Search epall;
|
static Policy::EPAll::Search epall;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "resources.hpp"
|
||||||
|
|
||||||
|
#include "fs_opendir.hpp"
|
||||||
|
#include "fs_closedir.hpp"
|
||||||
|
#include "fs_readdir.hpp"
|
||||||
#include "errno.hpp"
|
#include "errno.hpp"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -22,63 +27,89 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
namespace resources
|
|
||||||
|
int
|
||||||
|
resources::reset_umask(void)
|
||||||
{
|
{
|
||||||
int
|
umask(0);
|
||||||
reset_umask(void)
|
return 0;
|
||||||
{
|
}
|
||||||
umask(0);
|
|
||||||
return 0;
|
int
|
||||||
}
|
resources::maxout_rlimit(const int resource)
|
||||||
|
{
|
||||||
int
|
int rv;
|
||||||
maxout_rlimit(const int resource)
|
struct rlimit rlim;
|
||||||
{
|
|
||||||
int rv;
|
rlim.rlim_cur = RLIM_INFINITY;
|
||||||
struct rlimit rlim;
|
rlim.rlim_max = RLIM_INFINITY;
|
||||||
|
rv = ::setrlimit(resource,&rlim);
|
||||||
rlim.rlim_cur = RLIM_INFINITY;
|
if(rv == 0)
|
||||||
rlim.rlim_max = RLIM_INFINITY;
|
return 0;
|
||||||
rv = ::setrlimit(resource,&rlim);
|
|
||||||
if(rv == 0)
|
rv = ::getrlimit(resource,&rlim);
|
||||||
return 0;
|
if(rv == -1)
|
||||||
|
return -errno;
|
||||||
rv = ::getrlimit(resource,&rlim);
|
|
||||||
if(rv == -1)
|
rv = 0;
|
||||||
return -errno;
|
rlim.rlim_cur = rlim.rlim_max;
|
||||||
|
while(rv == 0)
|
||||||
rv = 0;
|
{
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
rv = ::setrlimit(resource,&rlim);
|
||||||
while(rv == 0)
|
rlim.rlim_max *= 2;
|
||||||
{
|
rlim.rlim_cur = rlim.rlim_max;
|
||||||
rv = ::setrlimit(resource,&rlim);
|
}
|
||||||
rlim.rlim_max *= 2;
|
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
int
|
||||||
}
|
resources::maxout_rlimit_nofile(void)
|
||||||
|
{
|
||||||
int
|
return maxout_rlimit(RLIMIT_NOFILE);
|
||||||
maxout_rlimit_nofile(void)
|
}
|
||||||
{
|
|
||||||
return maxout_rlimit(RLIMIT_NOFILE);
|
int
|
||||||
}
|
resources::maxout_rlimit_fsize(void)
|
||||||
|
{
|
||||||
int
|
return maxout_rlimit(RLIMIT_FSIZE);
|
||||||
maxout_rlimit_fsize(void)
|
}
|
||||||
{
|
|
||||||
return maxout_rlimit(RLIMIT_FSIZE);
|
int
|
||||||
}
|
resources::setpriority(const int prio_)
|
||||||
|
{
|
||||||
int
|
DIR *dir;
|
||||||
setpriority(const int prio)
|
struct dirent *e;
|
||||||
{
|
|
||||||
int rv;
|
::setpriority(PRIO_PROCESS,0,prio_);
|
||||||
const int SELF = 0;
|
|
||||||
|
dir = fs::opendir("/proc/self/task");
|
||||||
rv = ::setpriority(PRIO_PROCESS,SELF,prio);
|
if(dir == NULL)
|
||||||
|
return -errno;
|
||||||
return ((rv == -1) ? -errno : rv);
|
|
||||||
}
|
while(true)
|
||||||
|
{
|
||||||
|
pid_t tid;
|
||||||
|
|
||||||
|
e = fs::readdir(dir);
|
||||||
|
if(e == NULL)
|
||||||
|
break;
|
||||||
|
if(e->d_name[0] == '.')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tid = std::stoi(e->d_name);
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
::setpriority(PRIO_PROCESS,tid,prio_);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::closedir(dir);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,66 @@
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
|
||||||
|
#include "fmt/core.h"
|
||||||
|
|
||||||
|
#include "errno.hpp"
|
||||||
|
|
||||||
|
|
||||||
State state;
|
State state;
|
||||||
|
|
||||||
|
// static
|
||||||
|
// void
|
||||||
|
// _register_getattr(State *state_)
|
||||||
|
// {
|
||||||
|
// State::GetSet x;
|
||||||
|
|
||||||
|
// x.get = [state_]() -> std::string
|
||||||
|
// {
|
||||||
|
// return state_->getattr.to_string();
|
||||||
|
// };
|
||||||
|
// x.set = [state_](const std::string_view s_) -> int
|
||||||
|
// {
|
||||||
|
// return state_->getattr.from_string(s_);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// state_->set_getset("user.mergerfs.func.getattr",x);
|
||||||
|
// }
|
||||||
|
|
||||||
|
State::State()
|
||||||
|
{
|
||||||
|
// _register_getattr(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
State::set_getset(const std::string &name_,
|
||||||
|
const State::GetSet &gs_)
|
||||||
|
{
|
||||||
|
_getset[name_] = gs_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
State::get(const std::string &key_,
|
||||||
|
std::string &val_)
|
||||||
|
{
|
||||||
|
std::map<std::string,State::GetSet>::iterator i;
|
||||||
|
|
||||||
|
i = _getset.find(key_);
|
||||||
|
if((i == _getset.end()) || (!i->second.get))
|
||||||
|
return -ENOATTR;
|
||||||
|
|
||||||
|
val_ = i->second.get();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
State::set(const std::string &key_,
|
||||||
|
const std::string_view val_)
|
||||||
|
{
|
||||||
|
std::map<std::string,State::GetSet>::iterator i;
|
||||||
|
|
||||||
|
i = _getset.find(key_);
|
||||||
|
if((i == _getset.end()) || (!i->second.set))
|
||||||
|
return -ENOATTR;
|
||||||
|
|
||||||
|
return i->second.set(val_);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,18 @@
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
#include "fileinfo.hpp"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
constexpr int INVALID_BACKING_ID = -1;
|
constexpr int INVALID_BACKING_ID = -1;
|
||||||
|
|
||||||
class State
|
class State
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
State();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct OpenFile
|
struct OpenFile
|
||||||
{
|
{
|
||||||
|
|
@ -24,10 +31,27 @@ public:
|
||||||
FileInfo *fi;
|
FileInfo *fi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct GetSet
|
||||||
|
{
|
||||||
|
std::function<std::string()> get;
|
||||||
|
std::function<int(const std::string_view)> set;
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_getset(const std::string &name,
|
||||||
|
const State::GetSet &gs);
|
||||||
|
|
||||||
|
int get(const std::string &key,
|
||||||
|
std::string &val);
|
||||||
|
int set(const std::string &key,
|
||||||
|
const std::string_view val);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using OpenFileMap = boost::concurrent_flat_map<u64,OpenFile>;
|
using OpenFileMap = boost::concurrent_flat_map<u64,OpenFile>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string,GetSet> _getset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenFileMap open_files;
|
OpenFileMap open_files;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
455
src/str.cpp
455
src/str.cpp
|
|
@ -28,275 +28,254 @@
|
||||||
using std::istringstream;
|
using std::istringstream;
|
||||||
using std::set;
|
using std::set;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::string_view;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
namespace str
|
|
||||||
|
void
|
||||||
|
str::split(const string_view str_,
|
||||||
|
const char delimiter_,
|
||||||
|
vector<string> *result_)
|
||||||
{
|
{
|
||||||
void
|
size_t pos;
|
||||||
split(const char *str_,
|
size_t start;
|
||||||
const char delimiter_,
|
|
||||||
vector<string> *result_)
|
|
||||||
{
|
|
||||||
string part;
|
|
||||||
istringstream ss(str_);
|
|
||||||
|
|
||||||
while(std::getline(ss,part,delimiter_))
|
start = 0;
|
||||||
result_->push_back(part);
|
pos = str_.find(delimiter_,start);
|
||||||
}
|
while(pos != std::string_view::npos)
|
||||||
|
{
|
||||||
|
result_->push_back(std::string{str_.substr(start,pos)});
|
||||||
|
start = (pos + 1);
|
||||||
|
pos = str_.find(delimiter_,start);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
result_->push_back(std::string{str_.substr(start)});
|
||||||
split(const char *str_,
|
}
|
||||||
const char delimiter_,
|
|
||||||
set<string> *result_)
|
|
||||||
{
|
|
||||||
string part;
|
|
||||||
istringstream ss(str_);
|
|
||||||
|
|
||||||
while(std::getline(ss,part,delimiter_))
|
void
|
||||||
result_->insert(part);
|
str::split(const string_view str_,
|
||||||
}
|
const char delimiter_,
|
||||||
|
set<string> *result_)
|
||||||
|
{
|
||||||
|
size_t pos;
|
||||||
|
size_t start;
|
||||||
|
|
||||||
void
|
start = 0;
|
||||||
split(const string &str_,
|
pos = str_.find(delimiter_,start);
|
||||||
const char delimiter_,
|
while(pos != std::string_view::npos)
|
||||||
vector<string> *result_)
|
{
|
||||||
{
|
result_->insert(std::string{str_.substr(start,pos)});
|
||||||
return str::split(str_.c_str(),delimiter_,result_);
|
start = (pos + 1);
|
||||||
}
|
pos = str_.find(delimiter_,start);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
result_->insert(std::string{str_.substr(start)});
|
||||||
split(const string &str_,
|
}
|
||||||
const char delimiter_,
|
|
||||||
set<string> *result_)
|
|
||||||
{
|
|
||||||
return str::split(str_.c_str(),delimiter_,result_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
split_on_null(const char *str_,
|
str::split_on_null(const std::string_view str_,
|
||||||
const size_t len_,
|
std::vector<std::string> *result_)
|
||||||
std::vector<std::string> *result_)
|
{
|
||||||
{
|
const char *start;
|
||||||
const char *start;
|
const char *end;
|
||||||
const char *end;
|
|
||||||
|
|
||||||
start = str_;
|
start = str_.begin();
|
||||||
end = start + len_;
|
end = str_.end();
|
||||||
while(start < end)
|
while(start < end)
|
||||||
{
|
{
|
||||||
result_->emplace_back(start);
|
result_->emplace_back(start);
|
||||||
start += (result_->back().size() + 1);
|
start += (result_->back().size() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rsplit1(const string &str_,
|
str::rsplit1(const string_view &str_,
|
||||||
const char delimiter_,
|
const char delimiter_,
|
||||||
vector<string> *result_)
|
vector<string> *result_)
|
||||||
{
|
{
|
||||||
std::size_t off;
|
std::size_t off;
|
||||||
|
|
||||||
off = str_.rfind('=');
|
off = str_.rfind('=');
|
||||||
if(off == std::string::npos)
|
if(off == std::string::npos)
|
||||||
{
|
{
|
||||||
result_->push_back(str_);
|
result_->push_back(std::string{str_});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result_->push_back(str_.substr(0,off));
|
result_->push_back(std::string{str_.substr(0,off)});
|
||||||
result_->push_back(str_.substr(off+1));
|
result_->push_back(std::string{str_.substr(off+1)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
splitkv(const std::string_view &str_,
|
str::splitkv(const std::string_view str_,
|
||||||
const char delimiter_,
|
const char delimiter_,
|
||||||
std::string &key_,
|
std::string *key_,
|
||||||
std::string_view &val_)
|
std::string *val_)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
pos = str_.find(delimiter_);
|
pos = str_.find(delimiter_);
|
||||||
if(pos != std::string_view::npos)
|
if(pos != std::string_view::npos)
|
||||||
{
|
{
|
||||||
key_ = str_.substr(0,pos);
|
*key_ = str_.substr(0, pos);
|
||||||
val_ = str_.substr(pos + 1,
|
*val_ = str_.substr(pos + 1);
|
||||||
str_.size() - pos + 1);
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
*key_ = str_;
|
||||||
key_ = str_;
|
*val_ = "";
|
||||||
val_ = std::string_view{};
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
splitkv(const string &str_,
|
|
||||||
const char delimiter_,
|
|
||||||
string *key_,
|
|
||||||
string *val_)
|
|
||||||
{
|
|
||||||
istringstream iss;
|
|
||||||
std::string key;
|
|
||||||
std::string val;
|
|
||||||
|
|
||||||
iss.str(str_);
|
|
||||||
std::getline(iss,key,delimiter_);
|
|
||||||
std::getline(iss,val,'\0');
|
|
||||||
|
|
||||||
*key_ = key;
|
|
||||||
*val_ = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
string
|
|
||||||
join(const vector<string> &vec_,
|
|
||||||
const size_t substridx_,
|
|
||||||
const char sep_)
|
|
||||||
{
|
|
||||||
if(vec_.empty())
|
|
||||||
return string();
|
|
||||||
|
|
||||||
string rv = vec_[0].substr(substridx_);
|
|
||||||
for(size_t i = 1; i < vec_.size(); i++)
|
|
||||||
rv += sep_ + vec_[i].substr(substridx_);
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
string
|
|
||||||
join(const vector<string> &vec_,
|
|
||||||
const char sep_)
|
|
||||||
{
|
|
||||||
return str::join(vec_,0,sep_);
|
|
||||||
}
|
|
||||||
|
|
||||||
string
|
|
||||||
join(const set<string> &set_,
|
|
||||||
const char sep_)
|
|
||||||
{
|
|
||||||
string rv;
|
|
||||||
|
|
||||||
for(auto const &s : set_)
|
|
||||||
rv += s + sep_;
|
|
||||||
rv.pop_back();
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
longest_common_prefix_index(const vector<string> &vec_)
|
|
||||||
{
|
|
||||||
if(vec_.empty())
|
|
||||||
return string::npos;
|
|
||||||
|
|
||||||
for(size_t n = 0; n < vec_[0].size(); n++)
|
|
||||||
{
|
|
||||||
char chr = vec_[0][n];
|
|
||||||
for(size_t i = 1; i < vec_.size(); i++)
|
|
||||||
{
|
|
||||||
if(n >= vec_[i].size())
|
|
||||||
return n;
|
|
||||||
if(vec_[i][n] != chr)
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
string
|
|
||||||
longest_common_prefix(const vector<string> &vec_)
|
|
||||||
{
|
|
||||||
size_t idx;
|
|
||||||
|
|
||||||
idx = longest_common_prefix_index(vec_);
|
|
||||||
if(idx != string::npos)
|
|
||||||
return vec_[0].substr(0,idx);
|
|
||||||
|
|
||||||
|
string
|
||||||
|
str::join(const vector<string> &vec_,
|
||||||
|
const size_t substridx_,
|
||||||
|
const char sep_)
|
||||||
|
{
|
||||||
|
if(vec_.empty())
|
||||||
return string();
|
return string();
|
||||||
}
|
|
||||||
|
|
||||||
string
|
string rv = vec_[0].substr(substridx_);
|
||||||
remove_common_prefix_and_join(const vector<string> &vec_,
|
for(size_t i = 1; i < vec_.size(); i++)
|
||||||
const char sep_)
|
rv += sep_ + vec_[i].substr(substridx_);
|
||||||
{
|
|
||||||
size_t idx;
|
|
||||||
|
|
||||||
idx = str::longest_common_prefix_index(vec_);
|
return rv;
|
||||||
if(idx == string::npos)
|
}
|
||||||
idx = 0;
|
|
||||||
|
|
||||||
return str::join(vec_,idx,sep_);
|
string
|
||||||
}
|
str::join(const vector<string> &vec_,
|
||||||
|
const char sep_)
|
||||||
|
{
|
||||||
|
return str::join(vec_,0,sep_);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
string
|
||||||
erase_fnmatches(const vector<string> &patterns_,
|
str::join(const set<string> &set_,
|
||||||
vector<string> &strs_)
|
const char sep_)
|
||||||
{
|
{
|
||||||
vector<string>::iterator si;
|
string rv;
|
||||||
vector<string>::const_iterator pi;
|
|
||||||
|
|
||||||
si = strs_.begin();
|
for(auto const &s : set_)
|
||||||
while(si != strs_.end())
|
rv += s + sep_;
|
||||||
{
|
rv.pop_back();
|
||||||
int match = FNM_NOMATCH;
|
|
||||||
|
|
||||||
for(pi = patterns_.begin();
|
return rv;
|
||||||
pi != patterns_.end() && match != 0;
|
}
|
||||||
++pi)
|
|
||||||
{
|
|
||||||
match = fnmatch(pi->c_str(),si->c_str(),0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(match == 0)
|
size_t
|
||||||
si = strs_.erase(si);
|
str::longest_common_prefix_index(const vector<string> &vec_)
|
||||||
else
|
{
|
||||||
++si;
|
if(vec_.empty())
|
||||||
}
|
return string::npos;
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
for(size_t n = 0; n < vec_[0].size(); n++)
|
||||||
isprefix(const string &s0_,
|
{
|
||||||
const string &s1_)
|
char chr = vec_[0][n];
|
||||||
{
|
for(size_t i = 1; i < vec_.size(); i++)
|
||||||
return ((s0_.size() >= s1_.size()) &&
|
{
|
||||||
(s0_.compare(0,s1_.size(),s1_) == 0));
|
if(n >= vec_[i].size())
|
||||||
}
|
return n;
|
||||||
|
if(vec_[i][n] != chr)
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
return string::npos;
|
||||||
startswith(const string &str_,
|
}
|
||||||
const string &prefix_)
|
|
||||||
{
|
|
||||||
return ((str_.size() >= prefix_.size()) &&
|
|
||||||
(str_.compare(0,prefix_.size(),prefix_) == 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
string
|
||||||
endswith(const string &str_,
|
str::longest_common_prefix(const vector<string> &vec_)
|
||||||
const string &suffix_)
|
{
|
||||||
{
|
size_t idx;
|
||||||
if(suffix_.size() > str_.size())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return std::equal(suffix_.rbegin(),
|
idx = longest_common_prefix_index(vec_);
|
||||||
suffix_.rend(),
|
if(idx != string::npos)
|
||||||
str_.rbegin());
|
return vec_[0].substr(0,idx);
|
||||||
}
|
|
||||||
|
|
||||||
std::string
|
return string();
|
||||||
trim(const std::string &str_)
|
}
|
||||||
{
|
|
||||||
std::string rv;
|
|
||||||
|
|
||||||
rv = str_;
|
string
|
||||||
|
str::remove_common_prefix_and_join(const vector<string> &vec_,
|
||||||
|
const char sep_)
|
||||||
|
{
|
||||||
|
size_t idx;
|
||||||
|
|
||||||
while(!rv.empty() && (rv[0] == ' '))
|
idx = str::longest_common_prefix_index(vec_);
|
||||||
rv.erase(0);
|
if(idx == string::npos)
|
||||||
while(!rv.empty() && (rv[rv.size()-1] == ' '))
|
idx = 0;
|
||||||
rv.erase(rv.size()-1);
|
|
||||||
|
|
||||||
return rv;
|
return str::join(vec_,idx,sep_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
str::erase_fnmatches(const vector<string> &patterns_,
|
||||||
|
vector<string> &strs_)
|
||||||
|
{
|
||||||
|
vector<string>::iterator si;
|
||||||
|
vector<string>::const_iterator pi;
|
||||||
|
|
||||||
|
si = strs_.begin();
|
||||||
|
while(si != strs_.end())
|
||||||
|
{
|
||||||
|
int match = FNM_NOMATCH;
|
||||||
|
|
||||||
|
for(pi = patterns_.begin();
|
||||||
|
pi != patterns_.end() && match != 0;
|
||||||
|
++pi)
|
||||||
|
{
|
||||||
|
match = fnmatch(pi->c_str(),si->c_str(),0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(match == 0)
|
||||||
|
si = strs_.erase(si);
|
||||||
|
else
|
||||||
|
++si;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
str::isprefix(const string &s0_,
|
||||||
|
const string &s1_)
|
||||||
|
{
|
||||||
|
return ((s0_.size() >= s1_.size()) &&
|
||||||
|
(s0_.compare(0,s1_.size(),s1_) == 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
str::startswith(const string &str_,
|
||||||
|
const string &prefix_)
|
||||||
|
{
|
||||||
|
return ((str_.size() >= prefix_.size()) &&
|
||||||
|
(str_.compare(0,prefix_.size(),prefix_) == 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
str::endswith(const string &str_,
|
||||||
|
const string &suffix_)
|
||||||
|
{
|
||||||
|
if(suffix_.size() > str_.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return std::equal(suffix_.rbegin(),
|
||||||
|
suffix_.rend(),
|
||||||
|
str_.rbegin());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
str::trim(const std::string &str_)
|
||||||
|
{
|
||||||
|
std::string rv;
|
||||||
|
|
||||||
|
rv = str_;
|
||||||
|
|
||||||
|
while(!rv.empty() && (rv[0] == ' '))
|
||||||
|
rv.erase(0);
|
||||||
|
while(!rv.empty() && (rv[rv.size()-1] == ' '))
|
||||||
|
rv.erase(rv.size()-1);
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
33
src/str.hpp
33
src/str.hpp
|
|
@ -23,44 +23,29 @@
|
||||||
namespace str
|
namespace str
|
||||||
{
|
{
|
||||||
void
|
void
|
||||||
split(const char *str,
|
split(const std::string_view str,
|
||||||
const char delimiter,
|
|
||||||
std::vector<std::string> *result);
|
|
||||||
void
|
|
||||||
split(const std::string &str,
|
|
||||||
const char delimiter,
|
const char delimiter,
|
||||||
std::vector<std::string> *result);
|
std::vector<std::string> *result);
|
||||||
|
|
||||||
void
|
void
|
||||||
split(const char *str,
|
split(const std::string_view str,
|
||||||
const char delimiter,
|
const char delimiter,
|
||||||
std::set<std::string> *result);
|
std::set<std::string> *result);
|
||||||
void
|
|
||||||
split(const std::string &str,
|
|
||||||
const char delimiter,
|
|
||||||
std::set<std::string> *result);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
split_on_null(const char *str,
|
split_on_null(const std::string_view str,
|
||||||
const size_t len,
|
|
||||||
std::vector<std::string> *result);
|
std::vector<std::string> *result);
|
||||||
|
|
||||||
void
|
void
|
||||||
rsplit1(const std::string &str,
|
rsplit1(const std::string_view &str,
|
||||||
const char delimiter,
|
const char delimiter,
|
||||||
std::vector<std::string> *result);
|
std::vector<std::string> *result);
|
||||||
|
|
||||||
void
|
void
|
||||||
splitkv(const std::string &str,
|
splitkv(const std::string_view str,
|
||||||
const char delimiter,
|
|
||||||
std::string *key,
|
|
||||||
std::string *value);
|
|
||||||
|
|
||||||
void
|
|
||||||
splitkv(const std::string_view &str,
|
|
||||||
const char delimiter,
|
const char delimiter,
|
||||||
std::string &key,
|
std::string *key,
|
||||||
std::string_view &val);
|
std::string *value);
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
join(const std::vector<std::string> &vec,
|
join(const std::vector<std::string> &vec,
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "fuse_kernel.h"
|
#include "fuse_kernel.h"
|
||||||
|
#include "int_types.h"
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
@ -32,13 +30,13 @@ namespace symlinkify
|
||||||
inline
|
inline
|
||||||
bool
|
bool
|
||||||
can_be_symlink(const struct stat &st_,
|
can_be_symlink(const struct stat &st_,
|
||||||
const time_t timeout_)
|
const s64 timeout_)
|
||||||
{
|
{
|
||||||
if(S_ISDIR(st_.st_mode) ||
|
if(S_ISDIR(st_.st_mode) ||
|
||||||
(st_.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)))
|
(st_.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const time_t now = ::time(NULL);
|
const s64 now = ::time(NULL);
|
||||||
|
|
||||||
return (((now - st_.st_mtime) > timeout_) &&
|
return (((now - st_.st_mtime) > timeout_) &&
|
||||||
((now - st_.st_ctime) > timeout_));
|
((now - st_.st_ctime) > timeout_));
|
||||||
|
|
@ -48,13 +46,13 @@ namespace symlinkify
|
||||||
inline
|
inline
|
||||||
bool
|
bool
|
||||||
can_be_symlink(const struct fuse_statx &st_,
|
can_be_symlink(const struct fuse_statx &st_,
|
||||||
const time_t timeout_)
|
const s64 timeout_)
|
||||||
{
|
{
|
||||||
if(S_ISDIR(st_.mode) ||
|
if(S_ISDIR(st_.mode) ||
|
||||||
(st_.mode & (S_IWUSR|S_IWGRP|S_IWOTH)))
|
(st_.mode & (S_IWUSR|S_IWGRP|S_IWOTH)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const time_t now = ::time(NULL);
|
const s64 now = ::time(NULL);
|
||||||
|
|
||||||
return (((now - st_.mtime.tv_sec) > timeout_) &&
|
return (((now - st_.mtime.tv_sec) > timeout_) &&
|
||||||
((now - st_.ctime.tv_sec) > timeout_));
|
((now - st_.ctime.tv_sec) > timeout_));
|
||||||
|
|
@ -81,4 +79,34 @@ namespace symlinkify
|
||||||
st_->size = target_.size();
|
st_->size = target_.size();
|
||||||
st_->blocks = 0;
|
st_->blocks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
convert_if_can_be_symlink(const std::string &target_,
|
||||||
|
struct stat *st_,
|
||||||
|
const s64 timeout_)
|
||||||
|
{
|
||||||
|
if(timeout_ < 0)
|
||||||
|
return;
|
||||||
|
if(!symlinkify::can_be_symlink(*st_,timeout_))
|
||||||
|
return;
|
||||||
|
|
||||||
|
symlinkify::convert(target_,st_);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
convert_if_can_be_symlink(const std::string &target_,
|
||||||
|
fuse_statx *st_,
|
||||||
|
const s64 timeout_)
|
||||||
|
{
|
||||||
|
if(timeout_ < 0)
|
||||||
|
return;
|
||||||
|
if(!symlinkify::can_be_symlink(*st_,timeout_))
|
||||||
|
return;
|
||||||
|
|
||||||
|
symlinkify::convert(target_,st_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,38 +23,39 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
namespace str
|
std::string
|
||||||
|
str::to(const bool bool_)
|
||||||
{
|
{
|
||||||
std::string
|
return (bool_ ? "true" : "false");
|
||||||
to(const bool bool_)
|
}
|
||||||
{
|
|
||||||
return (bool_ ? "true" : "false");
|
std::string
|
||||||
}
|
str::to(const int int_)
|
||||||
|
{
|
||||||
std::string
|
return fmt::format("{}",int_);
|
||||||
to(const int int_)
|
}
|
||||||
{
|
|
||||||
return fmt::format("{}",int_);
|
std::string
|
||||||
}
|
str::to(const uint64_t uint64_)
|
||||||
|
{
|
||||||
std::string
|
return fmt::format("{}",uint64_);
|
||||||
to(const uint64_t uint64_)
|
}
|
||||||
{
|
|
||||||
return fmt::format("{}",uint64_);
|
std::string
|
||||||
}
|
str::to(const int64_t int64_)
|
||||||
|
{
|
||||||
std::string
|
return fmt::format("{}",int64_);
|
||||||
to(const std::string &s_)
|
}
|
||||||
{
|
|
||||||
return s_;
|
std::string
|
||||||
}
|
str::to(const std::string &s_)
|
||||||
|
{
|
||||||
std::string
|
return s_;
|
||||||
to(const fs::Path &path_)
|
}
|
||||||
{
|
|
||||||
return path_.string();
|
std::string
|
||||||
}
|
str::to(const std::filesystem::path &path_)
|
||||||
|
{
|
||||||
|
return path_.string();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "fs_path.hpp"
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -29,6 +28,7 @@ namespace str
|
||||||
std::string to(const bool);
|
std::string to(const bool);
|
||||||
std::string to(const int);
|
std::string to(const int);
|
||||||
std::string to(const uint64_t);
|
std::string to(const uint64_t);
|
||||||
|
std::string to(const int64_t);
|
||||||
std::string to(const std::string&);
|
std::string to(const std::string&);
|
||||||
std::string to(const fs::Path&);
|
std::string to(const std::filesystem::path&);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
class ToFromString
|
class ToFromString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual std::string to_string() const = 0;
|
virtual std::string to_string() const = 0;
|
||||||
virtual int from_string(const std::string &) = 0;
|
virtual int from_string(const std::string_view) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class ToFromWrapper : public ToFromString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int
|
int
|
||||||
from_string(const std::string &s_) final
|
from_string(const std::string_view s_) final
|
||||||
{
|
{
|
||||||
return str::from(s_,&_data);
|
return str::from(s_,&_data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue