diff --git a/src/branch.cpp b/src/branch.cpp index 9630f5c4..943e967f 100644 --- a/src/branch.cpp +++ b/src/branch.cpp @@ -18,8 +18,8 @@ #include "branch.hpp" #include "ef.hpp" -#include "fs.hpp" #include "fs_glob.hpp" +#include "fs_realpathize.hpp" #include "str.hpp" #include diff --git a/src/config.cpp b/src/config.cpp index 7bade626..28bec9a6 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -18,7 +18,6 @@ #include "ef.hpp" #include "errno.hpp" #include "from_string.hpp" -#include "fs.hpp" #include "num.hpp" #include "rwlock.hpp" #include "to_string.hpp" diff --git a/src/fs.cpp b/src/fs.cpp deleted file mode 100644 index 634be5eb..00000000 --- a/src/fs.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - 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 - -#include -#include -#include -#include - -#include "errno.hpp" -#include "fs_attr.hpp" -#include "fs_base_realpath.hpp" -#include "fs_base_stat.hpp" -#include "fs_exists.hpp" -#include "fs_path.hpp" -#include "fs_statvfs_cache.hpp" -#include "fs_xattr.hpp" -#include "str.hpp" - -using std::string; -using std::vector; - -namespace fs -{ - void - findallfiles(const vector &basepaths_, - const char *fusepath_, - vector *paths_) - { - string fullpath; - - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) - { - fullpath = fs::path::make(basepaths_[i],fusepath_); - - if(!fs::exists(fullpath)) - continue; - - paths_->push_back(fullpath); - } - } - - int - findonfs(const vector &basepaths, - const string &fusepath, - const int fd, - string &basepath) - { - int rv; - dev_t dev; - string fullpath; - struct stat st; - - rv = fs::fstat(fd,&st); - if(rv == -1) - return -1; - - dev = st.st_dev; - for(size_t i = 0, ei = basepaths.size(); i != ei; i++) - { - fullpath = fs::path::make(basepaths[i],fusepath); - - rv = fs::lstat(fullpath,&st); - if(rv == -1) - continue; - - if(st.st_dev != dev) - continue; - - basepath = basepaths[i]; - - return 0; - } - - return (errno=ENOENT,-1); - } - - void - realpathize(vector *strs_) - { - char *rv; - - for(size_t i = 0; i < strs_->size(); i++) - { - rv = fs::realpath((*strs_)[i]); - if(rv == NULL) - continue; - - (*strs_)[i] = rv; - - ::free(rv); - } - } - - int - getfl(const int fd) - { - return ::fcntl(fd,F_GETFL,0); - } - - int - setfl(const int fd, - const mode_t mode) - { - return ::fcntl(fd,F_SETFL,mode); - } -}; diff --git a/src/fs_findallfiles.cpp b/src/fs_findallfiles.cpp new file mode 100644 index 00000000..a7a60d42 --- /dev/null +++ b/src/fs_findallfiles.cpp @@ -0,0 +1,44 @@ +/* + ISC License + + Copyright (c) 2020, 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 "fs_exists.hpp" +#include "fs_path.hpp" + +#include +#include + +namespace fs +{ + void + findallfiles(const std::vector &basepaths_, + const char *fusepath_, + std::vector *paths_) + { + std::string fullpath; + + for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + { + fullpath = fs::path::make(basepaths_[i],fusepath_); + + if(!fs::exists(fullpath)) + continue; + + paths_->push_back(fullpath); + } + } +} diff --git a/src/fs.hpp b/src/fs_findallfiles.hpp similarity index 64% rename from src/fs.hpp rename to src/fs_findallfiles.hpp index bd374c90..ff3d81ed 100644 --- a/src/fs.hpp +++ b/src/fs_findallfiles.hpp @@ -1,5 +1,7 @@ /* - Copyright (c) 2016, Antonio SJ Musumeci + ISC License + + Copyright (c) 2020, 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 @@ -19,18 +21,10 @@ #include #include -#include -#include - namespace fs { - void findallfiles(const std::vector &basepaths, - const char *fusepath, - std::vector *paths); - - void realpathize(std::vector *strs); - - int getfl(const int fd); - int setfl(const int fd, - const mode_t mode); + void + findallfiles(const std::vector &basepaths, + const char *fusepath, + std::vector *paths); } diff --git a/src/fs_getfl.cpp b/src/fs_getfl.cpp new file mode 100644 index 00000000..891561db --- /dev/null +++ b/src/fs_getfl.cpp @@ -0,0 +1,28 @@ +/* + ISC License + + Copyright (c) 2020, 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 + +namespace fs +{ + int + getfl(const int fd_) + { + return ::fcntl(fd_,F_GETFL,0); + } +} diff --git a/src/fs_getfl.hpp b/src/fs_getfl.hpp new file mode 100644 index 00000000..ddb30034 --- /dev/null +++ b/src/fs_getfl.hpp @@ -0,0 +1,24 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +namespace fs +{ + int getfl(const int fd); +} diff --git a/src/fs_movefile.cpp b/src/fs_movefile.cpp index b010ec08..6ec357e3 100644 --- a/src/fs_movefile.cpp +++ b/src/fs_movefile.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_base_close.hpp" #include "fs_base_open.hpp" #include "fs_base_rename.hpp" @@ -25,6 +24,7 @@ #include "fs_clonepath.hpp" #include "fs_file_size.hpp" #include "fs_findonfs.hpp" +#include "fs_getfl.hpp" #include "fs_has_space.hpp" #include "fs_mktemp.hpp" #include "fs_path.hpp" diff --git a/src/fs_realpathize.cpp b/src/fs_realpathize.cpp new file mode 100644 index 00000000..a7c1f5d0 --- /dev/null +++ b/src/fs_realpathize.cpp @@ -0,0 +1,42 @@ +/* + ISC License + + Copyright (c) 2020, 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 "fs_base_realpath.hpp" + +#include +#include + +namespace fs +{ + void + realpathize(std::vector *strs_) + { + char *rv; + + for(size_t i = 0; i < strs_->size(); i++) + { + rv = fs::realpath((*strs_)[i]); + if(rv == NULL) + continue; + + (*strs_)[i] = rv; + + ::free(rv); + } + } +} diff --git a/src/fs_realpathize.hpp b/src/fs_realpathize.hpp new file mode 100644 index 00000000..dfd6270d --- /dev/null +++ b/src/fs_realpathize.hpp @@ -0,0 +1,28 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include +#include + +namespace fs +{ + void + realpathize(std::vector *strs); +} diff --git a/src/fs_setfl.cpp b/src/fs_setfl.cpp new file mode 100644 index 00000000..faf1b2e4 --- /dev/null +++ b/src/fs_setfl.cpp @@ -0,0 +1,29 @@ +/* + ISC License + + Copyright (c) 2020, 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 + +namespace fs +{ + int + setfl(const int fd_, + const mode_t mode_) + { + return ::fcntl(fd_,F_SETFL,mode_); + } +} diff --git a/src/fs_setfl.hpp b/src/fs_setfl.hpp new file mode 100644 index 00000000..9b146f10 --- /dev/null +++ b/src/fs_setfl.hpp @@ -0,0 +1,28 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include + +namespace fs +{ + int + setfl(const int fd, + const mode_t mode); +} diff --git a/src/fuse_getxattr.cpp b/src/fuse_getxattr.cpp index 517a9f30..98f730b7 100644 --- a/src/fuse_getxattr.cpp +++ b/src/fuse_getxattr.cpp @@ -17,6 +17,7 @@ #include "config.hpp" #include "errno.hpp" #include "fs_base_getxattr.hpp" +#include "fs_findallfiles.hpp" #include "fs_path.hpp" #include "fs_statvfs_cache.hpp" #include "str.hpp" diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index 9fab9e4c..d187eddc 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -22,6 +22,7 @@ #include "fs_base_close.hpp" #include "fs_base_ioctl.hpp" #include "fs_base_open.hpp" +#include "fs_findallfiles.hpp" #include "fs_path.hpp" #include "str.hpp" #include "ugid.hpp" diff --git a/src/policy.cpp b/src/policy.cpp index 2059cbf9..3e62a638 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -17,7 +17,6 @@ #include #include "buildvector.hpp" -#include "fs.hpp" #include "policy.hpp" #define POLICY(X,PP) (Policy(Policy::Enum::X,#X,Policy::Func::X,PP)) diff --git a/src/policy.hpp b/src/policy.hpp index 32fa9e11..9e722cd6 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -18,7 +18,6 @@ #include "branch.hpp" #include "category.hpp" -#include "fs.hpp" #include #include diff --git a/src/policy_epall.cpp b/src/policy_epall.cpp index d8c6033a..353395f8 100644 --- a/src/policy_epall.cpp +++ b/src/policy_epall.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_epff.cpp b/src/policy_epff.cpp index b4fdd6ee..ea360f69 100644 --- a/src/policy_epff.cpp +++ b/src/policy_epff.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_eplfs.cpp b/src/policy_eplfs.cpp index 6865a69e..f44581bb 100644 --- a/src/policy_eplfs.cpp +++ b/src/policy_eplfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_eplus.cpp b/src/policy_eplus.cpp index d20b5922..65a4ca3a 100644 --- a/src/policy_eplus.cpp +++ b/src/policy_eplus.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index 8d5e0051..b77604fa 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index 0cbf9892..ea772a35 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index 6067fbc0..45e096d1 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_lus.cpp b/src/policy_lus.cpp index 54466428..74cca0f1 100644 --- a/src/policy_lus.cpp +++ b/src/policy_lus.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index 69648ca5..d286cf1b 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_msplfs.cpp b/src/policy_msplfs.cpp index 6fde8c62..a479e5eb 100644 --- a/src/policy_msplfs.cpp +++ b/src/policy_msplfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_msplus.cpp b/src/policy_msplus.cpp index 32996920..6fc641dd 100644 --- a/src/policy_msplus.cpp +++ b/src/policy_msplus.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_mspmfs.cpp b/src/policy_mspmfs.cpp index 4a7c462e..f93a4439 100644 --- a/src/policy_mspmfs.cpp +++ b/src/policy_mspmfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index 01089ed1..c3eced2b 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" diff --git a/src/ugid.cpp b/src/ugid.cpp index 70ce91ad..368bbf8c 100644 --- a/src/ugid.cpp +++ b/src/ugid.cpp @@ -25,11 +25,11 @@ namespace ugid { void - initgroups(const uid_t uid, - const gid_t gid) + initgroups(const uid_t uid_, + const gid_t gid_) { static __thread gid_t_cache cache = {0}; - cache.initgroups(uid,gid); + cache.initgroups(uid_,gid_); } }