break fs.hpp up into separate files

This commit is contained in:
Antonio SJ Musumeci 2020-08-17 16:05:03 -04:00
parent ec15872a1f
commit 2696079601
30 changed files with 237 additions and 156 deletions

View File

@ -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 <string>

View File

@ -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"

View File

@ -1,122 +0,0 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
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 <string>
#include <vector>
#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#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<string> &basepaths_,
const char *fusepath_,
vector<string> *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<string> &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<string> *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);
}
};

44
src/fs_findallfiles.cpp Normal file
View File

@ -0,0 +1,44 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <string>
#include <vector>
namespace fs
{
void
findallfiles(const std::vector<std::string> &basepaths_,
const char *fusepath_,
std::vector<std::string> *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);
}
}
}

View File

@ -1,5 +1,7 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <string>
#include <vector>
#include <fcntl.h>
#include <stdint.h>
namespace fs
{
void findallfiles(const std::vector<std::string> &basepaths,
const char *fusepath,
std::vector<std::string> *paths);
void realpathize(std::vector<std::string> *strs);
int getfl(const int fd);
int setfl(const int fd,
const mode_t mode);
void
findallfiles(const std::vector<std::string> &basepaths,
const char *fusepath,
std::vector<std::string> *paths);
}

28
src/fs_getfl.cpp Normal file
View File

@ -0,0 +1,28 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <fcntl.h>
namespace fs
{
int
getfl(const int fd_)
{
return ::fcntl(fd_,F_GETFL,0);
}
}

24
src/fs_getfl.hpp Normal file
View File

@ -0,0 +1,24 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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);
}

View File

@ -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"

42
src/fs_realpathize.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <string>
#include <vector>
namespace fs
{
void
realpathize(std::vector<std::string> *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);
}
}
}

28
src/fs_realpathize.hpp Normal file
View File

@ -0,0 +1,28 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <string>
#include <vector>
namespace fs
{
void
realpathize(std::vector<std::string> *strs);
}

29
src/fs_setfl.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <fcntl.h>
namespace fs
{
int
setfl(const int fd_,
const mode_t mode_)
{
return ::fcntl(fd_,F_SETFL,mode_);
}
}

28
src/fs_setfl.hpp Normal file
View File

@ -0,0 +1,28 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
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 <fcntl.h>
namespace fs
{
int
setfl(const int fd,
const mode_t mode);
}

View File

@ -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"

View File

@ -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"

View File

@ -17,7 +17,6 @@
#include <vector>
#include "buildvector.hpp"
#include "fs.hpp"
#include "policy.hpp"
#define POLICY(X,PP) (Policy(Policy::Enum::X,#X,Policy::Func::X,PP))

View File

@ -18,7 +18,6 @@
#include "branch.hpp"
#include "category.hpp"
#include "fs.hpp"
#include <string>
#include <vector>

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -15,7 +15,6 @@
*/
#include "errno.hpp"
#include "fs.hpp"
#include "fs_exists.hpp"
#include "fs_info.hpp"
#include "fs_path.hpp"

View File

@ -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_);
}
}