diff --git a/src/chmod.cpp b/src/chmod.cpp index a37ffd3d..400a67d6 100644 --- a/src/chmod.cpp +++ b/src/chmod.cpp @@ -54,10 +54,9 @@ _chmod(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::chmod(i->full.c_str(),mode); + rv = ::chmod(paths[i].full.c_str(),mode); if(rv == -1) error = errno; } diff --git a/src/chown.cpp b/src/chown.cpp index 9aac1735..5c8230c3 100644 --- a/src/chown.cpp +++ b/src/chown.cpp @@ -56,10 +56,9 @@ _chown(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::lchown(i->full.c_str(),uid,gid); + rv = ::lchown(paths[i].full.c_str(),uid,gid); if(rv == -1) error = errno; } diff --git a/src/link.cpp b/src/link.cpp index 41cd7ac2..8fa1a0ed 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -92,10 +92,9 @@ _link(Policy::Func::Search searchFunc, return -errno; error = 0; - for(Paths::const_iterator - i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i) + for(size_t i = 0, ei = oldpaths.size(); i != ei; i++) { - rv = _single_link(searchFunc,srcmounts,minfreespace,i->base,oldpath,newpath); + rv = _single_link(searchFunc,srcmounts,minfreespace,oldpaths[i].base,oldpath,newpath); if(rv == -1) error = errno; } diff --git a/src/mkdir.cpp b/src/mkdir.cpp index 66193a79..1412d7ab 100644 --- a/src/mkdir.cpp +++ b/src/mkdir.cpp @@ -66,16 +66,17 @@ _mkdir(Policy::Func::Search searchFunc, return -errno; error = 0; - for(Paths::const_iterator - i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i) + for(size_t i = 0, ei = createpaths.size(); i != ei; i++) { - if(i->base != existingpath[0].base) + const string &createpath = createpaths[i].base; + + if(createpath != existingpath[0].base) { const mergerfs::ugid::SetResetGuard ugid(0,0); - fs::clonepath(existingpath[0].base,i->base,dirname); + fs::clonepath(existingpath[0].base,createpath,dirname); } - fullpath = fs::make_path(i->base,fusepath); + fullpath = fs::make_path(createpath,fusepath); rv = ::mkdir(fullpath.c_str(),mode); if(rv == -1) diff --git a/src/mknod.cpp b/src/mknod.cpp index 2340aba3..c2332553 100644 --- a/src/mknod.cpp +++ b/src/mknod.cpp @@ -69,16 +69,17 @@ _mknod(Policy::Func::Search searchFunc, return -errno; error = 0; - for(Paths::const_iterator - i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i) + for(size_t i = 0, ei = createpaths.size(); i != ei; i++) { - if(i->base != existingpath[0].base) + const string &createpath = createpaths[0].base; + + if(createpath != existingpath[0].base) { const mergerfs::ugid::SetResetGuard ugid(0,0); - fs::clonepath(existingpath[0].base,i->base,dirname); + fs::clonepath(existingpath[0].base,createpath,dirname); } - fullpath = fs::make_path(i->base,fusepath); + fullpath = fs::make_path(createpath,fusepath); rv = ::mknod(fullpath.c_str(),mode,dev); if(rv == -1) diff --git a/src/policy_all.cpp b/src/policy_all.cpp index 2ad14708..4113c2d0 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -36,6 +36,31 @@ using std::string; using std::vector; using std::size_t; +static +int +_all(const vector &basepaths, + const string &fusepath, + Paths &paths) +{ + int rv; + struct stat st; + string fullpath; + + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + const char *basepath; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + + rv = ::lstat(fullpath.c_str(),&st); + if(rv == 0) + paths.push_back(Path(basepath,fullpath)); + } + + return paths.empty() ? (errno=ENOENT,-1) : 0; +} + namespace mergerfs { int @@ -45,22 +70,6 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - int rv; - struct stat st; - string fullpath; - - for(vector::const_iterator - iter = basepaths.begin(), eiter = basepaths.end(); - iter != eiter; - ++iter) - { - fullpath = fs::make_path(*iter,fusepath); - - rv = ::lstat(fullpath.c_str(),&st); - if(rv == 0) - paths.push_back(Path(*iter,fullpath)); - } - - return paths.empty() ? (errno=ENOENT,-1) : 0; + return _all(basepaths,fusepath,paths); } } diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index 22bf8e56..2503439d 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -37,6 +37,162 @@ using std::string; using std::vector; using std::size_t; +static +inline +void +_calc_epmfs(const struct statvfs &fsstats, + const char *basepath, + fsblkcnt_t &epmfs, + const char *&epmfsbasepath, + fsblkcnt_t &mfs, + const char *&mfsbasepath) +{ + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if(spaceavail > epmfs) + { + epmfs = spaceavail; + epmfsbasepath = basepath; + } + + if(spaceavail > mfs) + { + mfs = spaceavail; + mfsbasepath = basepath; + } +} + +static +inline +void +_calc_mfs(const struct statvfs &fsstats, + const char *basepath, + fsblkcnt_t &mfs, + const char *&mfsbasepath) +{ + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if(spaceavail > mfs) + { + mfs = spaceavail; + mfsbasepath = basepath; + } +} + +static +inline +int +_try_statvfs(const char *basepath, + const string &fullpath, + fsblkcnt_t &epmfs, + const char *&epmfsbasepath, + fsblkcnt_t &mfs, + const char *&mfsbasepath) +{ + int rv; + struct statvfs fsstats; + + rv = ::statvfs(fullpath.c_str(),&fsstats); + if(rv == 0) + _calc_epmfs(fsstats,basepath,epmfs,epmfsbasepath,mfs,mfsbasepath); + + return rv; +} + +static +inline +int +_try_statvfs(const char *basepath, + fsblkcnt_t &mfs, + const char *&mfsbasepath) +{ + int rv; + struct statvfs fsstats; + + rv = ::statvfs(basepath,&fsstats); + if(rv == 0) + _calc_mfs(fsstats,basepath,mfs,mfsbasepath); + + return rv; +} + +static +int +_epmfs_create(const vector &basepaths, + const string &fusepath, + Paths &paths) + +{ + fsblkcnt_t epmfs; + fsblkcnt_t mfs; + const char *basepath; + const char *mfsbasepath; + const char *epmfsbasepath; + string fullpath; + + mfs = 0; + epmfs = 0; + mfsbasepath = NULL; + epmfsbasepath = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + + rv = _try_statvfs(basepath,fusepath,epmfs,epmfsbasepath,mfs,mfsbasepath); + if(rv == -1) + _try_statvfs(basepath,mfs,mfsbasepath); + } + + if(epmfsbasepath == NULL) + epmfsbasepath = mfsbasepath; + + paths.push_back(Path(epmfsbasepath, + fs::make_path(epmfsbasepath,fusepath))); + + return 0; +} + +static +int +_epmfs(const vector &basepaths, + const string &fusepath, + Paths &paths) + +{ + fsblkcnt_t epmfs; + const char *basepath; + const char *epmfsbasepath; + string fullpath; + + epmfs = 0; + epmfsbasepath = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + + rv = ::statvfs(fullpath.c_str(),&fsstats); + if(rv == 0) + _calc_mfs(fsstats,basepath,epmfs,epmfsbasepath); + } + + if(epmfsbasepath == NULL) + return (errno=ENOENT,-1); + + paths.push_back(Path(epmfsbasepath, + fs::make_path(epmfsbasepath,fusepath))); + + return 0; +} + namespace mergerfs { int @@ -46,60 +202,9 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - fsblkcnt_t existingmfs; - fsblkcnt_t generalmfs; - string fullpath; - string generalmfspath; - string existingmfspath; - vector::const_iterator iter = basepaths.begin(); - vector::const_iterator eiter = basepaths.end(); - - if(iter == eiter) - return (errno = ENOENT,-1); - - existingmfs = 0; - generalmfs = 0; - do - { - int rv; - struct statvfs fsstats; - const string &mountpoint = *iter; - - rv = ::statvfs(mountpoint.c_str(),&fsstats); - if(rv == 0) - { - fsblkcnt_t spaceavail; - struct stat st; - - spaceavail = (fsstats.f_frsize * fsstats.f_bavail); - if(spaceavail > generalmfs) - { - generalmfs = spaceavail; - generalmfspath = mountpoint; - } - - fullpath = fs::make_path(mountpoint,fusepath); - rv = ::lstat(fullpath.c_str(),&st); - if(rv == 0) - { - if(spaceavail > existingmfs) - { - existingmfs = spaceavail; - existingmfspath = mountpoint; - } - } - } - - ++iter; - } - while(iter != eiter); - - if(existingmfspath.empty()) - existingmfspath = generalmfspath; - - paths.push_back(Path(existingmfspath, - fullpath)); - - return 0; + if(type == Category::Enum::create) + return _epmfs_create(basepaths,fusepath,paths); + + return _epmfs(basepaths,fusepath,paths); } } diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index d81fa2d4..c26738fb 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -37,6 +37,34 @@ using std::string; using std::vector; using std::size_t; +static +int +_ff(const vector &basepaths, + const string &fusepath, + Paths &paths) +{ + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + struct stat st; + const char *basepath; + string fullpath; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + + rv = ::lstat(fullpath.c_str(),&st); + if(rv == -1) + continue; + + paths.push_back(Path(basepath,fullpath)); + + return 0; + } + + return (errno=ENOENT,-1); +} + namespace mergerfs { int @@ -46,26 +74,6 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - errno = ENOENT; - for(vector::const_iterator - iter = basepaths.begin(), eiter = basepaths.end(); - iter != eiter; - ++iter) - { - int rv; - struct stat st; - string fullpath; - - fullpath = fs::make_path(*iter,fusepath); - - rv = ::lstat(fullpath.c_str(),&st); - if(rv == 0) - { - paths.push_back(Path(*iter,fullpath)); - return 0; - } - } - - return -1; + return _ff(basepaths,fusepath,paths); } } diff --git a/src/policy_ffwp.cpp b/src/policy_ffwp.cpp index ab0dc45e..1b5cf5a5 100644 --- a/src/policy_ffwp.cpp +++ b/src/policy_ffwp.cpp @@ -36,6 +36,46 @@ using std::string; using std::vector; using std::size_t; +static +int +_ffwp(const vector &basepaths, + const string &fusepath, + Paths &paths) +{ + const char *fallback; + + fallback = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + struct stat st; + const char *basepath; + string fullpath; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + + rv = ::lstat(fullpath.c_str(),&st); + if(rv == 0) + { + paths.push_back(Path(basepath,fullpath)); + return 0; + } + else if(errno == EACCES) + { + fallback = basepath; + } + } + + if(fallback == NULL) + return (errno=ENOENT,-1); + + paths.push_back(Path(fallback, + fs::make_path(fallback,fusepath))); + + return 0; +} + namespace mergerfs { int @@ -45,36 +85,6 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - Path fallback; - - errno = ENOENT; - for(vector::const_iterator - iter = basepaths.begin(), eiter = basepaths.end(); - iter != eiter; - ++iter) - { - int rv; - struct stat st; - string fullpath; - - fullpath = fs::make_path(*iter,fusepath); - - rv = ::lstat(fullpath.c_str(),&st); - if(rv == 0) - { - paths.push_back(Path(*iter,fullpath)); - return 0; - } - else if(errno == EACCES) - { - fallback.base = *iter; - fallback.full = fullpath; - } - } - - if(!fallback.base.empty()) - return (paths.push_back(fallback),0); - - return -1; + return _ffwp(basepaths,fusepath,paths); } } diff --git a/src/policy_fwfs.cpp b/src/policy_fwfs.cpp index 219de38e..d31760fc 100644 --- a/src/policy_fwfs.cpp +++ b/src/policy_fwfs.cpp @@ -33,6 +33,77 @@ using std::string; using std::vector; using std::size_t; +using mergerfs::Policy; +using mergerfs::Category; + +static +int +_fwfs_create(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + Paths &paths) +{ + for(size_t i = 0, size = basepaths.size(); i != size; i++) + { + int rv; + const char *basepath; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + rv = ::statvfs(basepath,&fsstats); + if(rv == 0) + { + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if(spaceavail < minfreespace) + continue; + + paths.push_back(Path(basepath, + fs::make_path(basepath,fusepath))); + + return 0; + } + } + + return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); +} + +static +int +_fwfs(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + Paths &paths) +{ + for(size_t i = 0, size = basepaths.size(); i != size; i++) + { + int rv; + string fullpath; + const char *basepath; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + rv = ::statvfs(fullpath.c_str(),&fsstats); + if(rv == 0) + { + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if(spaceavail < minfreespace) + continue; + + paths.push_back(Path(basepath,fullpath)); + + return 0; + } + } + + return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); +} namespace mergerfs { @@ -43,28 +114,9 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - for(size_t i = 0, size = basepaths.size(); i != size; i++) - { - int rv; - const char *basepath; - struct statvfs fsstats; - - basepath = basepaths[i].c_str(); - rv = ::statvfs(basepath,&fsstats); - if(rv == 0) - { - fsblkcnt_t spaceavail; - - spaceavail = (fsstats.f_frsize * fsstats.f_bavail); - if(spaceavail > minfreespace) - { - paths.push_back(Path(basepath, - fs::make_path(basepath,fusepath))); - return 0; - } - } - } - - return mfs(type,basepaths,fusepath,minfreespace,paths); + if(type == Category::Enum::create) + return _fwfs_create(type,basepaths,fusepath,minfreespace,paths); + + return _fwfs(type,basepaths,fusepath,minfreespace,paths); } } diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index c972e4dd..9e844e3c 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -36,6 +36,98 @@ using std::string; using std::vector; using std::size_t; +using mergerfs::Policy; +using mergerfs::Category; + +static +int +_lfs_create(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + Paths &paths) +{ + fsblkcnt_t lfs; + const char *lfsstr; + + lfs = -1; + lfsstr = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + const char *basepath; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + rv = ::statvfs(basepath,&fsstats); + if(rv == 0) + { + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if((spaceavail > minfreespace) && + (spaceavail < lfs)) + { + lfs = spaceavail; + lfsstr = basepath; + } + } + } + + if(lfsstr == NULL) + return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); + + paths.push_back(Path(lfsstr, + fs::make_path(lfsstr,fusepath))); + + return 0; +} + +static +int +_lfs(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + Paths &paths) +{ + fsblkcnt_t lfs; + const char *lfsstr; + + lfs = -1; + lfsstr = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + string fullpath; + const char *basepath; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + rv = ::statvfs(fullpath.c_str(),&fsstats); + if(rv == 0) + { + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if((spaceavail > minfreespace) && + (spaceavail < lfs)) + { + lfs = spaceavail; + lfsstr = basepath; + } + } + } + + if(lfsstr == NULL) + return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); + + paths.push_back(Path(lfsstr, + fs::make_path(lfsstr,fusepath))); + + return 0; +} namespace mergerfs { @@ -46,39 +138,9 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - fsblkcnt_t lfs; - const char *lfsstr; - - lfs = -1; - lfsstr = NULL; - for(size_t i = 0, size = basepaths.size(); i != size; i++) - { - int rv; - const char *basepath; - struct statvfs fsstats; - - basepath = basepaths[i].c_str(); - rv = ::statvfs(basepath,&fsstats); - if(rv == 0) - { - fsblkcnt_t spaceavail; - - spaceavail = (fsstats.f_frsize * fsstats.f_bavail); - if((spaceavail > minfreespace) && - (spaceavail < lfs)) - { - lfs = spaceavail; - lfsstr = basepath; - } - } - } - - if(lfsstr == NULL) - return mfs(type,basepaths,fusepath,minfreespace,paths); - - paths.push_back(Path(lfsstr, - fs::make_path(lfsstr,fusepath))); - - return 0; + if(type == Category::Enum::create) + return _lfs_create(type,basepaths,fusepath,minfreespace,paths); + + return _lfs(type,basepaths,fusepath,minfreespace,paths); } } diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index 6e7c72fb..ddd9719c 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -34,6 +34,90 @@ using std::string; using std::vector; using std::size_t; +static +int +_mfs_create(const vector &basepaths, + const string &fusepath, + Paths &paths) +{ + fsblkcnt_t mfs; + const char *mfsstr; + + mfs = 0; + mfsstr = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + const char *basepath; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + rv = ::statvfs(basepath,&fsstats); + if(rv == 0) + { + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if(spaceavail > mfs) + { + mfs = spaceavail; + mfsstr = basepath; + } + } + } + + if(mfsstr == NULL) + return (errno=ENOENT,-1); + + paths.push_back(Path(mfsstr, + fs::make_path(mfsstr,fusepath))); + + return 0; +} + +static +int +_mfs(const vector &basepaths, + const string &fusepath, + Paths &paths) +{ + fsblkcnt_t mfs; + const char *mfsstr; + + mfs = 0; + mfsstr = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + string fullpath; + const char *basepath; + struct statvfs fsstats; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + rv = ::statvfs(fullpath.c_str(),&fsstats); + if(rv == 0) + { + fsblkcnt_t spaceavail; + + spaceavail = (fsstats.f_frsize * fsstats.f_bavail); + if(spaceavail > mfs) + { + mfs = spaceavail; + mfsstr = basepath; + } + } + } + + if(mfsstr == NULL) + return (errno=ENOENT,-1); + + paths.push_back(Path(mfsstr, + fs::make_path(mfsstr,fusepath))); + + return 0; +} + namespace mergerfs { int @@ -43,37 +127,9 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - fsblkcnt_t mfs; - size_t mfsidx; - - mfs = 0; - for(size_t i = 0, size = basepaths.size(); - i != size; - i++) - { - int rv; - struct statvfs fsstats; - - rv = ::statvfs(basepaths[i].c_str(),&fsstats); - if(rv == 0) - { - fsblkcnt_t spaceavail; - - spaceavail = (fsstats.f_frsize * fsstats.f_bavail); - if(spaceavail > mfs) - { - mfs = spaceavail; - mfsidx = i; - } - } - } - - if(mfs == 0) - return (errno=ENOENT,-1); - - paths.push_back(Path(basepaths[mfsidx], - fs::make_path(basepaths[mfsidx],fusepath))); - - return 0; + if(type == Category::Enum::create) + return _mfs_create(basepaths,fusepath,paths); + + return _mfs(basepaths,fusepath,paths); } } diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index bb01fb8d..e4f8cf1e 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -36,6 +36,44 @@ using std::string; using std::vector; using std::size_t; +static +int +_newest(const vector &basepaths, + const string &fusepath, + Paths &paths) +{ + time_t newest; + const char *neweststr; + + newest = 0; + neweststr = NULL; + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) + { + int rv; + struct stat st; + const char *basepath; + string fullpath; + + basepath = basepaths[i].c_str(); + fullpath = fs::make_path(basepath,fusepath); + + rv = ::lstat(fullpath.c_str(),&st); + if(rv == 0 && st.st_mtime > newest) + { + newest = st.st_mtime; + neweststr = basepath; + } + } + + if(neweststr == NULL) + return (errno=ENOENT,-1); + + paths.push_back(Path(neweststr, + fs::make_path(neweststr,fusepath))); + + return 0; +} + namespace mergerfs { int @@ -45,35 +83,6 @@ namespace mergerfs const size_t minfreespace, Paths &paths) { - time_t newest; - string npath; - vector::const_iterator niter; - - newest = 0; - errno = ENOENT; - for(vector::const_iterator - iter = basepaths.begin(), eiter = basepaths.end(); - iter != eiter; - ++iter) - { - int rv; - struct stat st; - string fullpath; - - fullpath = fs::make_path(*iter,fusepath); - - rv = ::lstat(fullpath.c_str(),&st); - if(rv == 0 && st.st_mtime > newest) - { - newest = st.st_mtime; - niter = iter; - npath = fullpath; - } - } - - if(newest) - return (paths.push_back(Path(*niter,npath)),0); - - return -1; + return _newest(basepaths,fusepath,paths); } } diff --git a/src/readdir.cpp b/src/readdir.cpp index 0d8f5817..b24b1952 100644 --- a/src/readdir.cpp +++ b/src/readdir.cpp @@ -57,15 +57,12 @@ _readdir(const vector &srcmounts, set found; struct stat st = {0}; - for(vector::const_iterator - iter = srcmounts.begin(), enditer = srcmounts.end(); - iter != enditer; - ++iter) + for(size_t i = 0, ei = srcmounts.size(); i != ei; i++) { DIR *dh; string basepath; - basepath = fs::make_path(*iter,dirname); + basepath = fs::make_path(srcmounts[i],dirname); dh = ::opendir(basepath.c_str()); if(!dh) continue; diff --git a/src/removexattr.cpp b/src/removexattr.cpp index 41a171e7..c6597fa6 100644 --- a/src/removexattr.cpp +++ b/src/removexattr.cpp @@ -58,10 +58,9 @@ _removexattr(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::lremovexattr(i->full.c_str(),attrname); + rv = ::lremovexattr(paths[i].full.c_str(),attrname); if(rv == -1) error = errno; } diff --git a/src/rename.cpp b/src/rename.cpp index 9594c77a..6755796e 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -91,10 +91,9 @@ _rename(Policy::Func::Search searchFunc, return -errno; error = 0; - for(Paths::const_iterator - i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i) + for(size_t i = 0, ei = oldpaths.size(); i != ei; i++) { - rv = _single_rename(searchFunc,srcmounts,minfreespace,*i,newpath); + rv = _single_rename(searchFunc,srcmounts,minfreespace,oldpaths[i],newpath); if(rv == -1) error = errno; } diff --git a/src/rmdir.cpp b/src/rmdir.cpp index 80023988..95768efd 100644 --- a/src/rmdir.cpp +++ b/src/rmdir.cpp @@ -54,10 +54,9 @@ _rmdir(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::rmdir(i->full.c_str()); + rv = ::rmdir(paths[i].full.c_str()); if(rv == -1) error = errno; } diff --git a/src/setxattr.cpp b/src/setxattr.cpp index c81aaaa4..0a5a14b3 100644 --- a/src/setxattr.cpp +++ b/src/setxattr.cpp @@ -259,10 +259,9 @@ _setxattr(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::lsetxattr(i->full.c_str(),attrname,attrval,attrvalsize,flags); + rv = ::lsetxattr(paths[i].full.c_str(),attrname,attrval,attrvalsize,flags); if(rv == -1) error = errno; } diff --git a/src/statfs.cpp b/src/statfs.cpp index 3ae39c35..5aab37ed 100644 --- a/src/statfs.cpp +++ b/src/statfs.cpp @@ -82,11 +82,11 @@ _statfs(const vector &srcmounts, vector::const_iterator iter; vector::const_iterator enditer; - for(iter = srcmounts.begin(), enditer = srcmounts.end(); iter != enditer; ++iter) + for(size_t i = 0, ei = srcmounts.size(); i != ei; i++) { int rv; struct statvfs fsstat; - rv = ::statvfs(iter->c_str(),&fsstat); + rv = ::statvfs(srcmounts[i].c_str(),&fsstat); if(rv != 0) continue; diff --git a/src/symlink.cpp b/src/symlink.cpp index d35ecac5..0e10bc09 100644 --- a/src/symlink.cpp +++ b/src/symlink.cpp @@ -57,12 +57,11 @@ _symlink(Policy::Func::Create createFunc, return -errno; error = 0; - for(Paths::iterator - i = newpathdirs.begin(), ei = newpathdirs.end(); i != ei; ++i) + for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++) { - i->full = fs::make_path(i->base,newpath); + newpathdirs[i].full = fs::make_path(newpathdirs[i].base,newpath); - rv = symlink(oldpath.c_str(),i->full.c_str()); + rv = symlink(oldpath.c_str(),newpathdirs[i].full.c_str()); if(rv == -1) error = errno; } diff --git a/src/truncate.cpp b/src/truncate.cpp index 01975589..40877450 100644 --- a/src/truncate.cpp +++ b/src/truncate.cpp @@ -57,10 +57,9 @@ _truncate(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::truncate(i->full.c_str(),size); + rv = ::truncate(paths[i].full.c_str(),size); if(rv == -1) error = errno; } diff --git a/src/unlink.cpp b/src/unlink.cpp index b334f051..f718273a 100644 --- a/src/unlink.cpp +++ b/src/unlink.cpp @@ -55,10 +55,9 @@ _unlink(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::unlink(i->full.c_str()); + rv = ::unlink(paths[i].full.c_str()); if(rv == -1) error = errno; } diff --git a/src/utimens.cpp b/src/utimens.cpp index d7cdf898..a2559627 100644 --- a/src/utimens.cpp +++ b/src/utimens.cpp @@ -57,10 +57,9 @@ _utimens(Policy::Func::Action actionFunc, return -errno; error = 0; - for(Paths::const_iterator - i = paths.begin(), ei = paths.end(); i != ei; ++i) + for(size_t i = 0, ei = paths.size(); i != ei; i++) { - rv = ::utimensat(0,i->full.c_str(),ts,AT_SYMLINK_NOFOLLOW); + rv = ::utimensat(0,paths[i].full.c_str(),ts,AT_SYMLINK_NOFOLLOW); if(rv == -1) error = errno; }