From e93c946198a5960f63b09c906e5c0c31c8c5cbf4 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Thu, 22 Dec 2016 15:53:17 -0500 Subject: [PATCH] limit need to explicitly call .c_str() --- src/fs_base_remove.hpp | 32 +++++++++++++++++++++++++++++++ src/fs_base_symlink.hpp | 42 +++++++++++++++++++++++++++++++++++++++++ src/fs_clonepath.cpp | 11 ++++++++++- src/fs_clonepath.hpp | 3 +++ src/fs_movefile.cpp | 4 ++-- src/link.cpp | 2 +- src/rename.cpp | 8 ++++---- src/symlink.cpp | 4 ++-- 8 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 src/fs_base_remove.hpp create mode 100644 src/fs_base_symlink.hpp diff --git a/src/fs_base_remove.hpp b/src/fs_base_remove.hpp new file mode 100644 index 00000000..777d98de --- /dev/null +++ b/src/fs_base_remove.hpp @@ -0,0 +1,32 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + remove(const std::string &pathname) + { + return ::remove(pathname.c_str()); + } +} diff --git a/src/fs_base_symlink.hpp b/src/fs_base_symlink.hpp new file mode 100644 index 00000000..4b438e71 --- /dev/null +++ b/src/fs_base_symlink.hpp @@ -0,0 +1,42 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + symlink(const std::string &oldpath, + const std::string &newpath) + { + return ::symlink(oldpath.c_str(),newpath.c_str()); + } + + static + inline + int + symlink(const char *oldpath, + const std::string &newpath) + { + return ::symlink(oldpath,newpath.c_str()); + } +} diff --git a/src/fs_clonepath.cpp b/src/fs_clonepath.cpp index 68e5396d..c81e6432 100644 --- a/src/fs_clonepath.cpp +++ b/src/fs_clonepath.cpp @@ -23,6 +23,7 @@ #include "fs_base_mkdir.hpp" #include "fs_base_stat.hpp" #include "fs_base_utime.hpp" +#include "fs_clonepath.hpp" #include "fs_path.hpp" #include "fs_xattr.hpp" @@ -62,7 +63,7 @@ namespace fs fs::path::dirname(dirname); if(!dirname.empty()) { - rv = fs::clonepath(fromsrc,tosrc,dirname.c_str()); + rv = fs::clonepath(fromsrc,tosrc,dirname); if(rv == -1) return -1; } @@ -105,4 +106,12 @@ namespace fs return 0; } + + int + clonepath(const std::string &from, + const std::string &to, + const std::string &relative) + { + return fs::clonepath(from,to,relative.c_str()); + } } diff --git a/src/fs_clonepath.hpp b/src/fs_clonepath.hpp index 007277f9..579e067c 100644 --- a/src/fs_clonepath.hpp +++ b/src/fs_clonepath.hpp @@ -21,4 +21,7 @@ namespace fs int clonepath(const std::string &from, const std::string &to, const char *relative); + int clonepath(const std::string &from, + const std::string &to, + const std::string &relative); } diff --git a/src/fs_movefile.cpp b/src/fs_movefile.cpp index 045295d7..1ca1fa54 100644 --- a/src/fs_movefile.cpp +++ b/src/fs_movefile.cpp @@ -72,7 +72,7 @@ namespace fs fusedir = fusepath; fs::path::dirname(fusedir); - rv = fs::clonepath(fdin_path,fdout_path,fusedir.c_str()); + rv = fs::clonepath(fdin_path,fdout_path,fusedir); if(rv == -1) return -1; @@ -91,7 +91,7 @@ namespace fs { fs::close(fdin); fs::close(fdout); - fs::unlink(fdout_path.c_str()); + fs::unlink(fdout_path); return -1; } diff --git a/src/link.cpp b/src/link.cpp index 3f128568..c48a25b1 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -49,7 +49,7 @@ _link_create_path_core(const string &oldbasepath, if(oldbasepath != newbasepath) { const ugid::SetRootGuard ugidGuard; - rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); + rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath); if(rv == -1) return errno; } diff --git a/src/rename.cpp b/src/rename.cpp index f01ed068..2d4811c5 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -21,6 +21,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_remove.hpp" #include "fs_base_rename.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" @@ -32,7 +33,6 @@ using std::string; using std::vector; using std::set; -using mergerfs::Policy; using namespace mergerfs; static @@ -54,7 +54,7 @@ void _remove(const vector &toremove) { for(size_t i = 0, ei = toremove.size(); i != ei; i++) - ::remove(toremove[i].c_str()); + fs::remove(toremove[i]); } static @@ -70,7 +70,7 @@ _rename(const std::string &oldbasepath, if(oldbasepath != newbasepath) { const ugid::SetRootGuard guard; - rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath.c_str()); + rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath); if(rv == -1) return -1; } @@ -173,7 +173,7 @@ _clonepath(Policy::Func::Search searchFunc, { const ugid::SetRootGuard ugidGuard; - fs::clonepath(*srcbasepath[0],dstbasepath,fusedirpath.c_str()); + fs::clonepath(*srcbasepath[0],dstbasepath,fusedirpath); } return POLICY_SUCCESS; diff --git a/src/symlink.cpp b/src/symlink.cpp index d41d01c0..5c1434f3 100644 --- a/src/symlink.cpp +++ b/src/symlink.cpp @@ -23,6 +23,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_symlink.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" @@ -31,7 +32,6 @@ using std::string; using std::vector; -using mergerfs::Policy; using namespace mergerfs; static @@ -56,7 +56,7 @@ _symlink_loop_core(const string &existingpath, fs::path::make(&newbasepath,newpath,fullnewpath); - rv = ::symlink(oldpath,fullnewpath.c_str()); + rv = fs::symlink(oldpath,fullnewpath); return error::calc(rv,error,errno); }