mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-01-20 07:02:46 +08:00
minor tweaks to filesystem utility functions
This commit is contained in:
parent
400537d711
commit
25a039942c
52
src/fs.cpp
52
src/fs.cpp
|
@ -100,8 +100,10 @@ namespace fs
|
||||||
{
|
{
|
||||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||||
|
|
||||||
if(fs::exists(fullpath))
|
if(!fs::exists(fullpath))
|
||||||
paths.push_back(fullpath);
|
continue;
|
||||||
|
|
||||||
|
paths.push_back(fullpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +147,19 @@ namespace fs
|
||||||
vector<string> &strs)
|
vector<string> &strs)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
size_t veclen;
|
||||||
glob_t gbuf = {0};
|
glob_t gbuf = {0};
|
||||||
|
|
||||||
|
veclen = patterns.size();
|
||||||
|
if(veclen == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
for(size_t i = 0; i < patterns.size(); i++)
|
glob(patterns[0].c_str(),flags,NULL,&gbuf);
|
||||||
{
|
|
||||||
glob(patterns[i].c_str(),flags,NULL,&gbuf);
|
flags = GLOB_APPEND;
|
||||||
flags = GLOB_APPEND;
|
for(size_t i = 1; i < veclen; i++)
|
||||||
}
|
glob(patterns[i].c_str(),flags,NULL,&gbuf);
|
||||||
|
|
||||||
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
|
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
|
||||||
strs.push_back(gbuf.gl_pathv[i]);
|
strs.push_back(gbuf.gl_pathv[i]);
|
||||||
|
@ -188,32 +195,33 @@ namespace fs
|
||||||
string &path)
|
string &path)
|
||||||
{
|
{
|
||||||
fsblkcnt_t mfs;
|
fsblkcnt_t mfs;
|
||||||
ssize_t mfsidx;
|
fsblkcnt_t spaceavail;
|
||||||
|
const string *mfsbasepath;
|
||||||
|
|
||||||
mfs = 0;
|
mfs = 0;
|
||||||
mfsidx = -1;
|
mfsbasepath = NULL;
|
||||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||||
{
|
{
|
||||||
struct statvfs st;
|
struct statvfs st;
|
||||||
const string &basepath = basepaths[i];
|
const string &basepath = basepaths[i];
|
||||||
|
|
||||||
if(fs::exists(basepath,st))
|
if(!fs::exists(basepath,st))
|
||||||
{
|
continue;
|
||||||
fsblkcnt_t spaceavail;
|
|
||||||
|
|
||||||
spaceavail = StatVFS::spaceavail(st);
|
spaceavail = StatVFS::spaceavail(st);
|
||||||
if((spaceavail > mfs) && (spaceavail >= minfreespace))
|
if(spaceavail < minfreespace)
|
||||||
{
|
continue;
|
||||||
mfs = spaceavail;
|
if(spaceavail <= mfs)
|
||||||
mfsidx = i;
|
continue;
|
||||||
}
|
|
||||||
}
|
mfs = spaceavail;
|
||||||
|
mfsbasepath = &basepaths[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mfsidx == -1)
|
if(mfsbasepath == NULL)
|
||||||
return (errno=ENOENT,-1);
|
return (errno=ENOENT,-1);
|
||||||
|
|
||||||
path = basepaths[mfsidx];
|
path = *mfsbasepath;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user