mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-02-01 10:55:17 +08:00
move Path object to separate file
This commit is contained in:
parent
23cca83742
commit
2bd44568a1
|
@ -52,7 +52,7 @@ _access(const fs::find::Func searchFunc,
|
|||
const int mask)
|
||||
{
|
||||
int rv;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
|
|
|
@ -47,14 +47,14 @@ _chmod(const fs::find::Func actionFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::chmod(i->full.c_str(),mode);
|
||||
|
|
|
@ -49,14 +49,14 @@ _chown(const fs::find::Func actionFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::lchown(i->full.c_str(),uid,gid);
|
||||
|
|
|
@ -56,8 +56,8 @@ _create(const fs::find::Func searchFunc,
|
|||
int rv;
|
||||
string path;
|
||||
string dirname;
|
||||
fs::Paths createpath;
|
||||
fs::Paths existingpath;
|
||||
Paths createpath;
|
||||
Paths existingpath;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
|
|
26
src/fs.hpp
26
src/fs.hpp
|
@ -29,6 +29,8 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "path.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using std::size_t;
|
||||
|
@ -36,30 +38,6 @@ namespace fs
|
|||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
struct Path
|
||||
{
|
||||
Path() {}
|
||||
|
||||
explicit
|
||||
Path(const string &b,
|
||||
const string &f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Path(const char *b,
|
||||
const string &f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
|
||||
string base;
|
||||
string full;
|
||||
};
|
||||
|
||||
typedef vector<Path> Paths;
|
||||
|
||||
string dirname(const string &path);
|
||||
string basename(const string &path);
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ _getattr(const fs::find::Func searchFunc,
|
|||
struct stat &buf)
|
||||
{
|
||||
int rv;
|
||||
fs::Paths path;
|
||||
Paths path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
|
|
|
@ -167,7 +167,7 @@ _getxattr_user_mergerfs_allpaths(const vector<string> &srcmounts,
|
|||
|
||||
static
|
||||
int
|
||||
_getxattr_user_mergerfs(const fs::Path &path,
|
||||
_getxattr_user_mergerfs(const Path &path,
|
||||
const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
const char *attrname,
|
||||
|
@ -200,7 +200,7 @@ _getxattr(const fs::find::Func searchFunc,
|
|||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
fs::Paths path;
|
||||
Paths path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
|
|
|
@ -93,7 +93,7 @@ _ioctl_dir_base(const fs::find::Func searchFunc,
|
|||
{
|
||||
int fd;
|
||||
int rv;
|
||||
fs::Paths path;
|
||||
Paths path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
|
|
|
@ -56,7 +56,7 @@ _single_link(const fs::find::Func searchFunc,
|
|||
if(rv == -1 && errno == ENOENT)
|
||||
{
|
||||
string newpathdir;
|
||||
fs::Paths foundpath;
|
||||
Paths foundpath;
|
||||
|
||||
newpathdir = fs::dirname(newpath);
|
||||
rv = searchFunc(srcmounts,newpathdir,minfreespace,foundpath);
|
||||
|
@ -85,14 +85,14 @@ _link(const fs::find::Func searchFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths oldpaths;
|
||||
Paths oldpaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = _single_link(searchFunc,srcmounts,minfreespace,i->base,oldpath,newpath);
|
||||
|
|
|
@ -78,7 +78,7 @@ _listxattr(const fs::find::Func searchFunc,
|
|||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
fs::Paths path;
|
||||
Paths path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
|
|
|
@ -52,8 +52,8 @@ _mkdir(const fs::find::Func searchFunc,
|
|||
int error;
|
||||
string dirname;
|
||||
string fullpath;
|
||||
fs::Paths createpaths;
|
||||
fs::Paths existingpath;
|
||||
Paths createpaths;
|
||||
Paths existingpath;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
|
@ -65,7 +65,7 @@ _mkdir(const fs::find::Func searchFunc,
|
|||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
|
||||
{
|
||||
if(i->base != existingpath[0].base)
|
||||
|
|
|
@ -55,8 +55,8 @@ _mknod(const fs::find::Func searchFunc,
|
|||
int error;
|
||||
string dirname;
|
||||
string fullpath;
|
||||
fs::Paths createpaths;
|
||||
fs::Paths existingpath;
|
||||
Paths createpaths;
|
||||
Paths existingpath;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
|
@ -68,7 +68,7 @@ _mknod(const fs::find::Func searchFunc,
|
|||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
|
||||
{
|
||||
if(i->base != existingpath[0].base)
|
||||
|
|
|
@ -50,7 +50,7 @@ _open(const fs::find::Func searchFunc,
|
|||
{
|
||||
int fd;
|
||||
int rv;
|
||||
fs::Paths path;
|
||||
Paths path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
|
|
55
src/path.hpp
Normal file
55
src/path.hpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __PATH_HPP__
|
||||
#define __PATH_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Path
|
||||
{
|
||||
Path() {}
|
||||
|
||||
explicit
|
||||
Path(const std::string &b,
|
||||
const std::string &f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Path(const char *b,
|
||||
const std::string &f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
|
||||
std::string base;
|
||||
std::string full;
|
||||
};
|
||||
|
||||
typedef std::vector<Path> Paths;
|
||||
|
||||
#endif /* __PATH_HPP__ */
|
|
@ -49,7 +49,7 @@ _readlink(const fs::find::Func searchFunc,
|
|||
const size_t size)
|
||||
{
|
||||
int rv;
|
||||
fs::Paths path;
|
||||
Paths path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
|
|
|
@ -50,14 +50,14 @@ _removexattr(const fs::find::Func actionFunc,
|
|||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::lremovexattr(i->full.c_str(),attrname);
|
||||
|
|
|
@ -44,7 +44,7 @@ int
|
|||
_single_rename(const fs::find::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const fs::Path &oldpath,
|
||||
const Path &oldpath,
|
||||
const string &newpath)
|
||||
{
|
||||
int rv;
|
||||
|
@ -54,7 +54,7 @@ _single_rename(const fs::find::Func searchFunc,
|
|||
if(rv == -1 && errno == ENOENT)
|
||||
{
|
||||
string dirname;
|
||||
fs::Paths newpathdir;
|
||||
Paths newpathdir;
|
||||
|
||||
dirname = fs::dirname(newpath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,newpathdir);
|
||||
|
@ -83,14 +83,14 @@ _rename(const fs::find::Func searchFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths oldpaths;
|
||||
Paths oldpaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = _single_rename(searchFunc,srcmounts,minfreespace,*i,newpath);
|
||||
|
|
|
@ -47,14 +47,14 @@ _rmdir(const fs::find::Func actionFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::rmdir(i->full.c_str());
|
||||
|
|
|
@ -252,14 +252,14 @@ _setxattr(const fs::find::Func actionFunc,
|
|||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::lsetxattr(i->full.c_str(),attrname,attrval,attrvalsize,flags);
|
||||
|
|
|
@ -48,7 +48,7 @@ _symlink(const fs::find::Func createFunc,
|
|||
int rv;
|
||||
int error;
|
||||
string newpathdir;
|
||||
fs::Paths newpathdirs;
|
||||
Paths newpathdirs;
|
||||
|
||||
newpathdir = fs::dirname(newpath);
|
||||
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
|
||||
|
@ -56,7 +56,7 @@ _symlink(const fs::find::Func createFunc,
|
|||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::iterator
|
||||
for(Paths::iterator
|
||||
i = newpathdirs.begin(), ei = newpathdirs.end(); i != ei; ++i)
|
||||
{
|
||||
i->full = fs::make_path(i->base,newpath);
|
||||
|
|
|
@ -49,14 +49,14 @@ _truncate(const fs::find::Func actionFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::truncate(i->full.c_str(),size);
|
||||
|
|
|
@ -47,14 +47,14 @@ _unlink(const fs::find::Func actionFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::unlink(i->full.c_str());
|
||||
|
|
|
@ -49,14 +49,14 @@ _utimens(const fs::find::Func actionFunc,
|
|||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::Paths paths;
|
||||
Paths paths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(fs::Paths::const_iterator
|
||||
for(Paths::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
{
|
||||
rv = ::utimensat(0,i->full.c_str(),ts,AT_SYMLINK_NOFOLLOW);
|
||||
|
|
Loading…
Reference in New Issue
Block a user