Skip to content

Commit

Permalink
find functions now return errors. closes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
trapexit committed Aug 23, 2014
1 parent 8f35406 commit cfe7609
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 111 deletions.
6 changes: 3 additions & 3 deletions src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ _access(const fs::SearchFunc searchFunc,
int rv;
fs::PathVector path;

searchFunc(srcmounts,fusepath,path);
if(path.empty())
return -ENOENT;
rv = searchFunc(srcmounts,fusepath,path);
if(rv == -1)
return -errno;

rv = ::eaccess(path[0].full.c_str(),mask);

Expand Down
6 changes: 3 additions & 3 deletions src/chmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ _chmod(const fs::SearchFunc searchFunc,
int error;
fs::PathVector paths;

searchFunc(srcmounts,fusepath,paths);
if(paths.empty())
return -ENOENT;
rv = searchFunc(srcmounts,fusepath,paths);
if(rv == -1)
return -errno;

rv = -1;
error = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/chown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ _chown(const fs::SearchFunc searchFunc,
int error;
fs::PathVector paths;

searchFunc(srcmounts,fusepath,paths);
if(paths.empty())
return -ENOENT;
rv = searchFunc(srcmounts,fusepath,paths);
if(rv == -1)
return -errno;

rv = -1;
error = 0;
Expand Down
13 changes: 7 additions & 6 deletions src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ _create(const fs::SearchFunc searchFunc,
uint64_t &fh)
{
int fd;
int rv;
string path;
string dirname;
fs::PathVector createpath;
fs::PathVector existingpath;

dirname = fs::dirname(fusepath);
searchFunc(srcmounts,dirname,existingpath);
if(existingpath.empty())
return -ENOENT;
rv = searchFunc(srcmounts,dirname,existingpath);
if(rv == -1)
return -errno;

createPathFunc(srcmounts,dirname,createpath);
if(createpath.empty())
return -ENOSPC;
rv = createPathFunc(srcmounts,dirname,createpath);
if(rv == -1)
return -errno;

if(createpath[0].base != existingpath[0].base)
fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
Expand Down
58 changes: 34 additions & 24 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,20 @@ namespace fs

namespace find
{
void
int
invalid(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
{
return;
return (errno = EINVAL,-1);
}

void
int
ff(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
{
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
Expand All @@ -515,22 +516,20 @@ namespace fs
path = fs::make_path(*iter,fusepath);
rv = ::lstat(path.c_str(),&st);
if(rv == 0)
{
paths.push_back(Path(*iter,path));
return;
}
return (paths.push_back(Path(*iter,path)),0);
}

return;
return -1;
}

void
int
ffwp(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
{
Path fallback;

errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
Expand All @@ -544,8 +543,7 @@ namespace fs
rv = ::lstat(path.c_str(),&st);
if(rv == 0)
{
paths.push_back(Path(*iter,path));
return;
return (paths.push_back(Path(*iter,path)),0);
}
else if(errno == EACCES)
{
Expand All @@ -555,12 +553,12 @@ namespace fs
}

if(!fallback.base.empty())
paths.push_back(fallback);
return (paths.push_back(fallback),0);

return;
return -1;
}

void
int
newest(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
Expand All @@ -570,6 +568,7 @@ namespace fs
vector<string>::const_iterator niter;

newest = 0;
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
Expand All @@ -589,16 +588,17 @@ namespace fs
}

if(newest)
paths.push_back(Path(*niter,npath));
return (paths.push_back(Path(*niter,npath)),0);

return;
return -1;
}

void
int
all(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
{
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
Expand All @@ -614,18 +614,20 @@ namespace fs
paths.push_back(Path(*iter,path));
}

return;
return paths.empty() ? -1 : 0;
}

void
int
mfs(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
{
fsblkcnt_t mfs = 0;
fsblkcnt_t mfs;
string mfspath;
string fullmfspath;

mfs = 0;
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
Expand All @@ -649,14 +651,17 @@ namespace fs
}
}

if(mfs == 0)
return -1;

fullmfspath = fs::make_path(mfspath,fusepath);

paths.push_back(Path(mfspath,fullmfspath));

return;
return 0;
}

void
int
epmfs(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
Expand All @@ -669,6 +674,9 @@ namespace fs
vector<string>::const_iterator iter = basepaths.begin();
vector<string>::const_iterator eiter = basepaths.end();

if(iter == eiter)
return (errno = ENOENT,-1);

do
{
int rv;
Expand Down Expand Up @@ -709,10 +717,10 @@ namespace fs

paths.push_back(Path(existingmfspath,path));

return;
return 0;
}

void
int
rand(const vector<string> &basepaths,
const string fusepath,
PathVector &paths)
Expand All @@ -727,6 +735,8 @@ namespace fs
fusepath);

paths.push_back(Path(randombasepath,randomfullpath));

return 0;
}
}
};
50 changes: 25 additions & 25 deletions src/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace fs
};

typedef vector<Path> PathVector;
typedef void (*SearchFunc)(const vector<string>&,const string,PathVector&);
typedef int (*SearchFunc)(const vector<string>&,const string,PathVector&);

string dirname(const string path);
string basename(const string path);
Expand Down Expand Up @@ -112,30 +112,30 @@ namespace fs

namespace find
{
void invalid(const vector<string> &basepaths,
const string fusepath,
PathVector &paths);
void ff(const vector<string> &basepaths,
const string fusepath,
PathVector &paths);
void ffwp(const vector<string> &paths,
const string fusepath,
PathVector &rv);
void newest(const vector<string> &paths,
const string fusepath,
PathVector &rv);
void all(const vector<string> &paths,
const string fusepath,
PathVector &rv);
void mfs(const vector<string> &paths,
const string fusepath,
PathVector &rv);
void epmfs(const vector<string> &paths,
const string fusepath,
PathVector &rv);
void rand(const vector<string> &paths,
const string fusepath,
PathVector &rv);
int invalid(const vector<string> &basepaths,
const string fusepath,
PathVector &paths);
int ff(const vector<string> &basepaths,
const string fusepath,
PathVector &paths);
int ffwp(const vector<string> &paths,
const string fusepath,
PathVector &rv);
int newest(const vector<string> &paths,
const string fusepath,
PathVector &rv);
int all(const vector<string> &paths,
const string fusepath,
PathVector &rv);
int mfs(const vector<string> &paths,
const string fusepath,
PathVector &rv);
int epmfs(const vector<string> &paths,
const string fusepath,
PathVector &rv);
int rand(const vector<string> &paths,
const string fusepath,
PathVector &rv);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/getattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ _getattr(const fs::SearchFunc searchFunc,
int rv;
fs::PathVector paths;

searchFunc(srcmounts,fusepath,paths);
if(paths.empty())
return -ENOENT;
rv = searchFunc(srcmounts,fusepath,paths);
if(rv == -1)
return -errno;

rv = ::lstat(paths[0].full.c_str(),&buf);

Expand Down
6 changes: 3 additions & 3 deletions src/getxattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ _getxattr(const fs::SearchFunc searchFunc,
int rv;
fs::PathVector paths;

searchFunc(srcmounts,fusepath,paths);
if(paths.empty())
return -ENOENT;
rv = searchFunc(srcmounts,fusepath,paths);
if(rv == -1)
return -errno;

if(!strcmp(attrname,"user.mergerfs.basepath"))
rv = ::_getxattr_from_string(buf,count,paths[0].base);
Expand Down
6 changes: 3 additions & 3 deletions src/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ _link(const fs::SearchFunc searchFunc,
int error;
fs::PathVector paths;

searchFunc(srcmounts,from,paths);
if(paths.empty())
return -ENOENT;
rv = searchFunc(srcmounts,from,paths);
if(rv == -1)
return -errno;

rv = -1;
error = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/listxattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ _listxattr(const fs::SearchFunc searchFunc,
int rv;
fs::PathVector paths;

searchFunc(srcmounts,fusepath,paths);
if(paths.empty())
return -ENOENT;
rv = searchFunc(srcmounts,fusepath,paths);
if(rv == -1)
return -errno;

rv = ::llistxattr(paths[0].full.c_str(),list,size);

Expand Down
8 changes: 4 additions & 4 deletions src/mkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ _mkdir(const fs::SearchFunc searchFunc,
return -EEXIST;

dirname = fs::dirname(fusepath);
searchFunc(srcmounts,dirname,existingpath);
if(existingpath.empty())
return -ENOENT;
rv = searchFunc(srcmounts,dirname,existingpath);
if(rv == -1)
return -errno;

createPathFunc(srcmounts,dirname,createpath);
rv = createPathFunc(srcmounts,dirname,createpath);
if(createpath[0].base != existingpath[0].base)
fs::clonepath(existingpath[0].base,createpath[0].base,dirname);

Expand Down
6 changes: 3 additions & 3 deletions src/mknod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ _mknod(const fs::SearchFunc searchFunc,
return -EEXIST;

dirname = fs::dirname(fusepath);
searchFunc(srcmounts,dirname,existingpath);
if(existingpath.empty())
return -ENOENT;
rv = searchFunc(srcmounts,dirname,existingpath);
if(rv == -1)
return -errno;

createPathFunc(srcmounts,dirname,createpath);
if(existingpath[0].base != createpath[0].base)
Expand Down
Loading

0 comments on commit cfe7609

Please sign in to comment.