Browse Source

make symlink function like mknod/mkdir. closes #204

pull/205/head
Antonio SJ Musumeci 9 years ago
parent
commit
ea325755a7
  1. 31
      src/symlink.cpp

31
src/symlink.cpp

@ -22,6 +22,7 @@
#include <string> #include <string>
#include "config.hpp" #include "config.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp" #include "fs_path.hpp"
#include "rv.hpp" #include "rv.hpp"
#include "rwlock.hpp" #include "rwlock.hpp"
@ -30,10 +31,12 @@
using std::string; using std::string;
using std::vector; using std::vector;
using mergerfs::Policy; using mergerfs::Policy;
using namespace mergerfs;
static static
int int
_symlink(Policy::Func::Create createFunc,
_symlink(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace, const size_t minfreespace,
const string &oldpath, const string &oldpath,
@ -41,20 +44,33 @@ _symlink(Policy::Func::Create createFunc,
{ {
int rv; int rv;
int error; int error;
string newpathdir;
string dirname;
string existingpath;
vector<string> newpathdirs; vector<string> newpathdirs;
newpathdir = fs::path::dirname(newpath);
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
dirname = fs::path::dirname(newpath);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1)
return -errno;
rv = createFunc(srcmounts,dirname,minfreespace,newpathdirs);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
error = -1; error = -1;
for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++) for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++)
{ {
fs::path::append(newpathdirs[i],newpath);
string &newpathdir = newpathdirs[i];
if(newpathdir != existingpath)
{
const ugid::SetRootGuard ugidGuard;
fs::clonepath(existingpath,newpathdir,dirname);
}
fs::path::append(newpathdir,newpath);
rv = symlink(oldpath.c_str(),newpathdirs[i].c_str());
rv = symlink(oldpath.c_str(),newpathdir.c_str());
error = calc_error(rv,error,errno); error = calc_error(rv,error,errno);
} }
@ -75,7 +91,8 @@ namespace mergerfs
const ugid::Set ugid(fc->uid,fc->gid); const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock); const rwlock::ReadGuard readlock(&config.srcmountslock);
return _symlink(config.symlink,
return _symlink(config.getattr,
config.symlink,
config.srcmounts, config.srcmounts,
config.minfreespace, config.minfreespace,
oldpath, oldpath,

Loading…
Cancel
Save