mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
remove longest common prefix from fsname. closes #38
This commit is contained in:
parent
90b0fcd5f5
commit
5dd072962b
3 changed files with 74 additions and 3 deletions
|
|
@ -133,7 +133,9 @@ set_fsname(struct fuse_args &args,
|
|||
{
|
||||
std::string fsname;
|
||||
|
||||
fsname = "-ofsname=" + str::join(config.srcmounts,':');
|
||||
fsname =
|
||||
"-ofsname=" +
|
||||
str::remove_common_prefix_and_join(config.srcmounts,':');
|
||||
|
||||
fuse_opt_insert_arg(&args,1,fsname.c_str());
|
||||
}
|
||||
|
|
|
|||
58
src/str.cpp
58
src/str.cpp
|
|
@ -46,15 +46,69 @@ namespace str
|
|||
|
||||
string
|
||||
join(const vector<string> &vec,
|
||||
const size_t substridx,
|
||||
const char sep)
|
||||
{
|
||||
if(vec.empty())
|
||||
return string();
|
||||
|
||||
string rv = vec[0];
|
||||
string rv = vec[0].substr(substridx);
|
||||
for(size_t i = 1; i < vec.size(); i++)
|
||||
rv += sep + vec[i];
|
||||
rv += sep + vec[i].substr(substridx);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
string
|
||||
join(const vector<string> &vec,
|
||||
const char sep)
|
||||
{
|
||||
return str::join(vec,0,sep);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return string();
|
||||
}
|
||||
|
||||
string
|
||||
remove_common_prefix_and_join(const vector<string> &vec,
|
||||
const char sep)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
idx = str::longest_common_prefix_index(vec);
|
||||
if(idx == string::npos)
|
||||
idx = 0;
|
||||
|
||||
return str::join(vec,idx,sep);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
src/str.hpp
15
src/str.hpp
|
|
@ -34,5 +34,20 @@ namespace str
|
|||
|
||||
std::string
|
||||
join(const std::vector<std::string> &vec,
|
||||
const size_t substridx,
|
||||
const char sep);
|
||||
|
||||
std::string
|
||||
join(const std::vector<std::string> &vec,
|
||||
const char sep);
|
||||
|
||||
size_t
|
||||
longest_common_prefix_index(const std::vector<std::string> &vec);
|
||||
|
||||
std::string
|
||||
longest_common_prefix(const std::vector<std::string> &vec);
|
||||
|
||||
std::string
|
||||
remove_common_prefix_and_join(const std::vector<std::string> &vec,
|
||||
const char sep);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue