Browse Source

Merge pull request #517 from trapexit/cleanup

policy return cleanup
pull/518/head
trapexit 6 years ago
committed by GitHub
parent
commit
47bf58eae9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/create.cpp
  2. 34
      src/fs_base_setxattr.hpp
  3. 4
      src/fs_xattr.cpp
  4. 11
      src/link.cpp
  5. 10
      src/mkdir.cpp
  6. 10
      src/mknod.cpp
  7. 21
      src/policy.hpp
  8. 8
      src/policy_all.cpp
  9. 8
      src/policy_epall.cpp
  10. 12
      src/policy_epff.cpp
  11. 10
      src/policy_eplfs.cpp
  12. 10
      src/policy_eplus.cpp
  13. 10
      src/policy_epmfs.cpp
  14. 2
      src/policy_eprand.cpp
  15. 2
      src/policy_erofs.cpp
  16. 10
      src/policy_ff.cpp
  17. 2
      src/policy_invalid.cpp
  18. 10
      src/policy_lfs.cpp
  19. 10
      src/policy_lus.cpp
  20. 10
      src/policy_mfs.cpp
  21. 8
      src/policy_newest.cpp
  22. 2
      src/policy_rand.cpp
  23. 22
      src/rename.cpp
  24. 10
      src/symlink.cpp

6
src/create.cpp

@ -84,19 +84,17 @@ _create(Policy::Func::Search searchFunc,
int rv; int rv;
string fullpath; string fullpath;
string fusedirpath; string fusedirpath;
const char *fusedirpathcstr;
vector<const string*> createpaths; vector<const string*> createpaths;
vector<const string*> existingpaths; vector<const string*> existingpaths;
fusedirpath = fusepath; fusedirpath = fusepath;
fs::path::dirname(fusedirpath); fs::path::dirname(fusedirpath);
fusedirpathcstr = fusedirpath.c_str();
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
rv = searchFunc(srcmounts,fusedirpath,minfreespace,existingpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
rv = createFunc(srcmounts,fusedirpath,minfreespace,createpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;

34
src/fs_base_setxattr.hpp

@ -18,29 +18,47 @@
#pragma once #pragma once
#include <sys/types.h>
#include "errno.hpp" #include "errno.hpp"
#include "xattr.hpp" #include "xattr.hpp"
#include <sys/types.h>
#include <string>
namespace fs namespace fs
{ {
static static
inline inline
int int
lsetxattr(const std::string &path,
const char *name,
const void *value,
const size_t size,
const int flags)
lsetxattr(const char *path_,
const char *name_,
const void *value_,
const size_t size_,
const int flags_)
{ {
#ifdef USE_XATTR #ifdef USE_XATTR
return ::lsetxattr(path.c_str(),name,value,size,flags);
return ::lsetxattr(path_,name_,value_,size_,flags_);
#else #else
return (errno=ENOTSUP,-1); return (errno=ENOTSUP,-1);
#endif #endif
} }
static
inline
int
lsetxattr(const std::string &path_,
const std::string &name_,
const void *value_,
const size_t size_,
const int flags_)
{
return fs::lsetxattr(path_.c_str(),
name_.c_str(),
value_,
size_,
flags_);
}
static static
inline inline
int int

4
src/fs_xattr.cpp

@ -295,8 +295,8 @@ namespace fs
const string &value, const string &value,
const int flags) const int flags)
{ {
return fs::lsetxattr(path.c_str(),
key.c_str(),
return fs::lsetxattr(path,
key,
value.data(), value.data(),
value.size(), value.size(),
flags); flags);

11
src/link.cpp

@ -99,7 +99,8 @@ _link_create_path(Policy::Func::Search searchFunc,
newfusedirpath = newfusepath; newfusedirpath = newfusepath;
fs::path::dirname(newfusedirpath); fs::path::dirname(newfusedirpath);
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepaths);
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -120,25 +121,23 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc,
{ {
int rv; int rv;
string newfusedirpath; string newfusedirpath;
const char *newfusedirpathcstr;
vector<const string*> newbasepath; vector<const string*> newbasepath;
newfusedirpath = newfusepath; newfusedirpath = newfusepath;
fs::path::dirname(newfusedirpath); fs::path::dirname(newfusedirpath);
newfusedirpathcstr = newfusedirpath.c_str();
rv = createFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath);
rv = createFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
if(rv == -1) if(rv == -1)
return -1; return -1;
if(oldbasepath != *newbasepath[0]) if(oldbasepath != *newbasepath[0])
return (errno=EXDEV,-1); return (errno=EXDEV,-1);
rv = searchFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath);
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
if(rv == -1) if(rv == -1)
return -1; return -1;
return fs::clonepath_as_root(*newbasepath[0],oldbasepath,newfusedirpathcstr);
return fs::clonepath_as_root(*newbasepath[0],oldbasepath,newfusedirpath);
} }
static static

10
src/mkdir.cpp

@ -68,7 +68,7 @@ int
_mkdir_loop(const string &existingpath, _mkdir_loop(const string &existingpath,
const vector<const string*> &createpaths, const vector<const string*> &createpaths,
const char *fusepath, const char *fusepath,
const char *fusedirpath,
const string &fusedirpath,
const mode_t mode, const mode_t mode,
const mode_t umask) const mode_t umask)
{ {
@ -102,24 +102,22 @@ _mkdir(Policy::Func::Search searchFunc,
{ {
int rv; int rv;
string fusedirpath; string fusedirpath;
const char *fusedirpathcstr;
vector<const string*> createpaths; vector<const string*> createpaths;
vector<const string*> existingpaths; vector<const string*> existingpaths;
fusedirpath = fusepath; fusedirpath = fusepath;
fs::path::dirname(fusedirpath); fs::path::dirname(fusedirpath);
fusedirpathcstr = fusedirpath.c_str();
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
rv = searchFunc(srcmounts,fusedirpath,minfreespace,existingpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
rv = createFunc(srcmounts,fusedirpath,minfreespace,createpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
return _mkdir_loop(*existingpaths[0],createpaths, return _mkdir_loop(*existingpaths[0],createpaths,
fusepath,fusedirpathcstr,mode,umask);
fusepath,fusedirpath,mode,umask);
} }
namespace mergerfs namespace mergerfs

10
src/mknod.cpp

@ -71,7 +71,7 @@ int
_mknod_loop(const string &existingpath, _mknod_loop(const string &existingpath,
const vector<const string*> &createpaths, const vector<const string*> &createpaths,
const char *fusepath, const char *fusepath,
const char *fusedirpath,
const string &fusedirpath,
const mode_t mode, const mode_t mode,
const mode_t umask, const mode_t umask,
const dev_t dev) const dev_t dev)
@ -107,24 +107,22 @@ _mknod(Policy::Func::Search searchFunc,
{ {
int rv; int rv;
string fusedirpath; string fusedirpath;
const char *fusedirpathcstr;
vector<const string*> createpaths; vector<const string*> createpaths;
vector<const string*> existingpaths; vector<const string*> existingpaths;
fusedirpath = fusepath; fusedirpath = fusepath;
fs::path::dirname(fusedirpath); fs::path::dirname(fusedirpath);
fusedirpathcstr = fusedirpath.c_str();
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
rv = searchFunc(srcmounts,fusedirpath,minfreespace,existingpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
rv = createFunc(srcmounts,fusedirpath,minfreespace,createpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
return _mknod_loop(*existingpaths[0],createpaths, return _mknod_loop(*existingpaths[0],createpaths,
fusepath,fusedirpathcstr,
fusepath,fusedirpath,
mode,umask,dev); mode,umask,dev);
} }

21
src/policy.hpp

@ -16,19 +16,12 @@
#pragma once #pragma once
#include <string>
#include <vector>
#include <map>
#include "fs.hpp"
#include "category.hpp" #include "category.hpp"
#include "fs.hpp"
#define POLICY_SUCCESS 0
#define POLICY_FAIL -1
#define POLICY_SUCCEEDED(RV) ((RV) == POLICY_SUCCESS)
#define POLICY_FAILED(RV) ((RV) == POLICY_FAIL)
#define POLICY_FAIL_ERRNO(ERRNO) (errno=ERRNO,POLICY_FAIL)
#define POLICY_FAIL_ENOENT POLICY_FAIL_ERRNO(ENOENT)
#include <map>
#include <string>
#include <vector>
namespace mergerfs namespace mergerfs
{ {
@ -88,6 +81,12 @@ namespace mergerfs
return func(T,b,c,d,e); return func(T,b,c,d,e);
} }
int
operator()(cstrvec &b,const string &c,cuint64_t d,cstrptrvec &e)
{
return func(T,b,c.c_str(),d,e);
}
private: private:
const Ptr func; const Ptr func;
}; };

8
src/policy_all.cpp

@ -49,9 +49,9 @@ _all_create(const vector<string> &basepaths,
} }
if(paths.empty()) if(paths.empty())
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -75,9 +75,9 @@ _all_other(const vector<string> &basepaths,
} }
if(paths.empty()) if(paths.empty())
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
return POLICY_SUCCESS;
return 0;
} }
namespace mergerfs namespace mergerfs

8
src/policy_epall.cpp

@ -56,9 +56,9 @@ _epall_create(const vector<string> &basepaths,
} }
if(paths.empty()) if(paths.empty())
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -82,9 +82,9 @@ _epall_other(const vector<string> &basepaths,
} }
if(paths.empty()) if(paths.empty())
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
return POLICY_SUCCESS;
return 0;
} }
namespace mergerfs namespace mergerfs

12
src/policy_epff.cpp

@ -59,15 +59,15 @@ _epff_create(const vector<string> &basepaths,
paths.push_back(basepath); paths.push_back(basepath);
return POLICY_SUCCESS;
return 0;
} }
if(fallback == NULL) if(fallback == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(fallback); paths.push_back(fallback);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -89,10 +89,10 @@ _epff_other(const vector<string> &basepaths,
paths.push_back(basepath); paths.push_back(basepath);
return POLICY_SUCCESS;
return 0;
} }
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
} }
static static
@ -122,7 +122,7 @@ namespace mergerfs
int rv; int rv;
rv = _epff(type,basepaths,fusepath,minfreespace,paths); rv = _epff(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

10
src/policy_eplfs.cpp

@ -65,11 +65,11 @@ _eplfs_create(const vector<string> &basepaths,
} }
if(eplfsbasepath == NULL) if(eplfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(eplfsbasepath); paths.push_back(eplfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -103,11 +103,11 @@ _eplfs_other(const vector<string> &basepaths,
} }
if(eplfsbasepath == NULL) if(eplfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(eplfsbasepath); paths.push_back(eplfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -136,7 +136,7 @@ namespace mergerfs
int rv; int rv;
rv = _eplfs(type,basepaths,fusepath,minfreespace,paths); rv = _eplfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::lfs(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::lfs(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

10
src/policy_eplus.cpp

@ -65,11 +65,11 @@ _eplus_create(const vector<string> &basepaths,
} }
if(eplusbasepath == NULL) if(eplusbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(eplusbasepath); paths.push_back(eplusbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -103,11 +103,11 @@ _eplus_other(const vector<string> &basepaths,
} }
if(eplusbasepath == NULL) if(eplusbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(eplusbasepath); paths.push_back(eplusbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -136,7 +136,7 @@ namespace mergerfs
int rv; int rv;
rv = _eplus(type,basepaths,fusepath,minfreespace,paths); rv = _eplus(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::lus(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::lus(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

10
src/policy_epmfs.cpp

@ -65,11 +65,11 @@ _epmfs_create(const vector<string> &basepaths,
} }
if(epmfsbasepath == NULL) if(epmfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(epmfsbasepath); paths.push_back(epmfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -103,11 +103,11 @@ _epmfs_other(const vector<string> &basepaths,
} }
if(epmfsbasepath == NULL) if(epmfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(epmfsbasepath); paths.push_back(epmfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -136,7 +136,7 @@ namespace mergerfs
int rv; int rv;
rv = _epmfs(type,basepaths,fusepath,minfreespace,paths); rv = _epmfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

2
src/policy_eprand.cpp

@ -37,7 +37,7 @@ namespace mergerfs
int rv; int rv;
rv = Policy::Func::epall(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::epall(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_SUCCEEDED(rv))
if(rv == 0)
std::random_shuffle(paths.begin(),paths.end()); std::random_shuffle(paths.begin(),paths.end());
return rv; return rv;

2
src/policy_erofs.cpp

@ -32,6 +32,6 @@ namespace mergerfs
const uint64_t minfreespace, const uint64_t minfreespace,
vector<const string*> &paths) vector<const string*> &paths)
{ {
return POLICY_FAIL_ERRNO(EROFS);
return (errno=EROFS,-1);
} }
} }

10
src/policy_ff.cpp

@ -52,15 +52,15 @@ _ff_create(const vector<string> &basepaths,
paths.push_back(basepath); paths.push_back(basepath);
return POLICY_SUCCESS;
return 0;
} }
if(fallback == NULL) if(fallback == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(fallback); paths.push_back(fallback);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -82,10 +82,10 @@ _ff_other(const vector<string> &basepaths,
paths.push_back(basepath); paths.push_back(basepath);
return POLICY_SUCCESS;
return 0;
} }
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
} }
namespace mergerfs namespace mergerfs

2
src/policy_invalid.cpp

@ -32,6 +32,6 @@ namespace mergerfs
const uint64_t minfreespace, const uint64_t minfreespace,
vector<const string*> &paths) vector<const string*> &paths)
{ {
return POLICY_FAIL_ERRNO(EINVAL);
return (errno=EINVAL,-1);
} }
} }

10
src/policy_lfs.cpp

@ -60,11 +60,11 @@ _lfs_create(const vector<string> &basepaths,
} }
if(lfsbasepath == NULL) if(lfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(lfsbasepath); paths.push_back(lfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -98,11 +98,11 @@ _lfs_other(const vector<string> &basepaths,
} }
if(lfsbasepath == NULL) if(lfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(lfsbasepath); paths.push_back(lfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -132,7 +132,7 @@ namespace mergerfs
int rv; int rv;
rv = _lfs(type,basepaths,fusepath,minfreespace,paths); rv = _lfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

10
src/policy_lus.cpp

@ -60,11 +60,11 @@ _lus_create(const vector<string> &basepaths,
} }
if(lusbasepath == NULL) if(lusbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(lusbasepath); paths.push_back(lusbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -98,11 +98,11 @@ _lus_other(const vector<string> &basepaths,
} }
if(lusbasepath == NULL) if(lusbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(lusbasepath); paths.push_back(lusbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -131,7 +131,7 @@ namespace mergerfs
int rv; int rv;
rv = _lus(type,basepaths,fusepath,minfreespace,paths); rv = _lus(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

10
src/policy_mfs.cpp

@ -56,11 +56,11 @@ _mfs_create(const vector<string> &basepaths,
} }
if(mfsbasepath == NULL) if(mfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(mfsbasepath); paths.push_back(mfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -94,11 +94,11 @@ _mfs_other(const vector<string> &basepaths,
} }
if(mfsbasepath == NULL) if(mfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(mfsbasepath); paths.push_back(mfsbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -126,7 +126,7 @@ namespace mergerfs
int rv; int rv;
rv = _mfs(type,basepaths,fusepath,paths); rv = _mfs(type,basepaths,fusepath,paths);
if(POLICY_FAILED(rv))
if(rv == -1)
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
return rv; return rv;

8
src/policy_newest.cpp

@ -61,11 +61,11 @@ _newest_create(const vector<string> &basepaths,
} }
if(newestbasepath == NULL) if(newestbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(newestbasepath); paths.push_back(newestbasepath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -97,11 +97,11 @@ _newest_other(const vector<string> &basepaths,
} }
if(newestbasepath == NULL) if(newestbasepath == NULL)
return POLICY_FAIL_ENOENT;
return (errno=ENOENT,-1);
paths.push_back(newestbasepath); paths.push_back(newestbasepath);
return POLICY_SUCCESS;
return 0;
} }
namespace mergerfs namespace mergerfs

2
src/policy_rand.cpp

@ -37,7 +37,7 @@ namespace mergerfs
int rv; int rv;
rv = Policy::Func::all(type,basepaths,fusepath,minfreespace,paths); rv = Policy::Func::all(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_SUCCEEDED(rv))
if(rv == 0)
std::random_shuffle(paths.begin(),paths.end()); std::random_shuffle(paths.begin(),paths.end());
return rv; return rv;

22
src/rename.cpp

@ -112,13 +112,13 @@ _rename_create_path(Policy::Func::Search searchFunc,
vector<const string*> oldbasepaths; vector<const string*> oldbasepaths;
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
if(POLICY_FAILED(rv))
if(rv == -1)
return -errno; return -errno;
string newfusedirpath = newfusepath; string newfusedirpath = newfusepath;
fs::path::dirname(newfusedirpath); fs::path::dirname(newfusedirpath);
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
if(POLICY_FAILED(rv))
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
if(rv == -1)
return -errno; return -errno;
error = -1; error = -1;
@ -151,13 +151,13 @@ _clonepath(Policy::Func::Search searchFunc,
int rv; int rv;
vector<const string*> srcbasepath; vector<const string*> srcbasepath;
rv = searchFunc(srcmounts,fusedirpath.c_str(),minfreespace,srcbasepath);
if(POLICY_FAILED(rv))
rv = searchFunc(srcmounts,fusedirpath,minfreespace,srcbasepath);
if(rv == -1)
return -errno; return -errno;
fs::clonepath_as_root(*srcbasepath[0],dstbasepath,fusedirpath); fs::clonepath_as_root(*srcbasepath[0],dstbasepath,fusedirpath);
return POLICY_SUCCESS;
return 0;
} }
static static
@ -176,14 +176,14 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc,
newfusedirpath = newfusepath; newfusedirpath = newfusepath;
fs::path::dirname(newfusedirpath); fs::path::dirname(newfusedirpath);
rv = createFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
if(POLICY_FAILED(rv))
rv = createFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
if(rv == -1)
return rv; return rv;
if(oldbasepath == *newbasepath[0]) if(oldbasepath == *newbasepath[0])
return _clonepath(searchFunc,srcmounts,minfreespace,oldbasepath,newfusedirpath); return _clonepath(searchFunc,srcmounts,minfreespace,oldbasepath,newfusedirpath);
return POLICY_FAIL_ERRNO(EXDEV);
return (errno=EXDEV,-1);
} }
static static
@ -218,7 +218,7 @@ _rename_preserve_path_core(Policy::Func::Search searchFunc,
rv = _clonepath_if_would_create(searchFunc,createFunc, rv = _clonepath_if_would_create(searchFunc,createFunc,
srcmounts,minfreespace, srcmounts,minfreespace,
oldbasepath,oldfusepath,newfusepath); oldbasepath,oldfusepath,newfusepath);
if(POLICY_SUCCEEDED(rv))
if(rv == 0)
rv = fs::rename(oldfullpath,newfullpath); rv = fs::rename(oldfullpath,newfullpath);
} }
@ -248,7 +248,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
vector<const string*> oldbasepaths; vector<const string*> oldbasepaths;
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
if(POLICY_FAILED(rv))
if(rv == -1)
return -errno; return -errno;
error = -1; error = -1;

10
src/symlink.cpp

@ -57,7 +57,7 @@ _symlink_loop(const string &existingpath,
const vector<const string*> newbasepaths, const vector<const string*> newbasepaths,
const char *oldpath, const char *oldpath,
const char *newpath, const char *newpath,
const char *newdirpath)
const string &newdirpath)
{ {
int rv; int rv;
int error; int error;
@ -89,24 +89,22 @@ _symlink(Policy::Func::Search searchFunc,
{ {
int rv; int rv;
string newdirpath; string newdirpath;
const char *newdirpathcstr;
vector<const string*> newbasepaths; vector<const string*> newbasepaths;
vector<const string*> existingpaths; vector<const string*> existingpaths;
newdirpath = newpath; newdirpath = newpath;
fs::path::dirname(newdirpath); fs::path::dirname(newdirpath);
newdirpathcstr = newdirpath.c_str();
rv = searchFunc(srcmounts,newdirpathcstr,minfreespace,existingpaths);
rv = searchFunc(srcmounts,newdirpath,minfreespace,existingpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,newdirpathcstr,minfreespace,newbasepaths);
rv = createFunc(srcmounts,newdirpath,minfreespace,newbasepaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
return _symlink_loop(*existingpaths[0],newbasepaths, return _symlink_loop(*existingpaths[0],newbasepaths,
oldpath,newpath,newdirpathcstr);
oldpath,newpath,newdirpath);
} }
namespace mergerfs namespace mergerfs

Loading…
Cancel
Save