1616
1717#include < regex>
1818
19- std::filesystem::path get_parent_dir_path (const std::filesystem::path &file_path) {
19+ std::filesystem::path get_parent_dir_path (const std::filesystem::path& file_path)
20+ {
2021 START_LOG (capio_syscall (SYS_gettid), " call(file_path=%s)" , file_path.c_str ());
21- if (file_path == file_path.root_path ()) {
22+ if (file_path == file_path.root_path ())
23+ {
2224 return file_path;
2325 }
2426 const size_t pos = file_path.native ().rfind (' /' );
25- if (pos == std::string::npos) {
27+ if (pos == std::string::npos)
28+ {
2629 LOG (" invalid file_path in get_parent_dir_path" );
2730 }
2831 return {file_path.native ().substr (0 , pos)};
2932}
3033
31- inline bool in_dir (const std::string &path, const std::string &glob) {
34+ inline bool in_dir (const std::string& path, const std::string& glob)
35+ {
3236 const size_t res = path.find (' /' , glob.length () - 1 );
3337 return res != std::string::npos;
3438}
3539
36- inline bool is_directory (int dirfd) {
40+ inline bool is_directory (int dirfd)
41+ {
3742 START_LOG (capio_syscall (SYS_gettid), " call(dirfd=%d)" , dirfd);
3843 struct stat path_stat = {0 };
3944
4045 int tmp = fstat (dirfd, &path_stat);
41- if (tmp != 0 ) {
46+ if (tmp != 0 )
47+ {
4248 LOG (" Error at is_directory(dirfd=%d) -> %d: %d (%s)" , dirfd, tmp, errno,
4349 std::strerror (errno));
4450 return -1 ;
4551 }
4652 return S_ISDIR (path_stat.st_mode ) == 1 ;
4753}
4854
49- inline bool is_prefix (const std::filesystem::path &path_1, const std::filesystem::path &path_2) {
55+ inline bool is_prefix (const std::filesystem::path& path_1, const std::filesystem::path& path_2)
56+ {
5057 const auto relpath = path_2.lexically_relative (path_1);
5158 return !relpath.empty () && relpath.native ().rfind (" .." , 0 ) != 0 ;
5259}
5360
5461/*
5562 * Returns true if any of the paths in the list contains any of the forbidden paths.
5663 */
57- inline bool is_forbidden_path (const std::string_view &path) {
64+ inline bool is_forbidden_path (const std::string_view& path)
65+ {
5866 return std::any_of (CAPIO_DIR_FORBIDDEN_PATHS.cbegin (), CAPIO_DIR_FORBIDDEN_PATHS.cend (),
59- [&path](const std::string_view &forbidden_path) {
67+ [&path](const std::string_view& forbidden_path)
68+ {
6069 return path.find (forbidden_path) != std::string_view::npos;
6170 });
6271}
6372
64- inline bool is_capio_dir (const std::filesystem::path &path_to_check) {
73+ inline bool is_capio_dir (const std::filesystem::path& path_to_check)
74+ {
6575 START_LOG (capio_syscall (SYS_gettid), " call(path_to_check=%s)" , path_to_check.c_str ());
6676
6777 const auto res = get_capio_dir ().compare (path_to_check) == 0 ;
6878 LOG (" is_capio_dir:%s" , res ? " yes" : " no" );
6979 return res;
7080}
7181
72- inline bool is_capio_path (const std::filesystem::path &path_to_check) {
82+ inline bool is_capio_path (const std::filesystem::path& path_to_check)
83+ {
7384 START_LOG (capio_syscall (SYS_gettid), " call(path_to_check=%s)" , path_to_check.c_str ());
7485
7586 // check if path_to_check begins with CAPIO_DIR
@@ -86,13 +97,15 @@ inline bool is_capio_path(const std::filesystem::path &path_to_check) {
8697 * @param replacement
8798 * @return
8899 */
89- [[nodiscard]] static std::string replaceSymbol (const std::string &str, char symbol,
90- const std::string &replacement) {
100+ [[nodiscard]] static std::string replaceSymbol (const std::string& str, char symbol,
101+ const std::string& replacement)
102+ {
91103 std::string result = str;
92- size_t pos = 0 ;
104+ size_t pos = 0 ;
93105
94106 // Find the symbol and replace it
95- while ((pos = result.find (symbol, pos)) != std::string::npos) {
107+ while ((pos = result.find (symbol, pos)) != std::string::npos)
108+ {
96109 result.replace (pos, 1 , replacement);
97110 pos += replacement.length (); // Move past the replacement
98111 }
@@ -105,14 +118,15 @@ inline bool is_capio_path(const std::filesystem::path &path_to_check) {
105118 * @param capio_path String to convert
106119 * @return std::regex compiled with the corresponding c++ regex
107120 */
108- [[maybe_unused]] [[nodiscard]] static std::regex generateCapioRegex (const std::string &capio_path) {
121+ [[maybe_unused]] [[nodiscard]] static std::regex generateCapioRegex (const std::string& capio_path)
122+ {
109123 START_LOG (gettid (), " call(capio_path=%s)" , capio_path.c_str ());
110124 auto computed = replaceSymbol (capio_path, ' .' , " \\ ." );
111- computed = replaceSymbol (computed, ' /' , " \\ /" );
112- computed = replaceSymbol (computed, ' *' , R"( [a-zA-Z0-9\/\.\-_:]*)" );
113- computed = replaceSymbol (computed, ' +' , " ." );
125+ computed = replaceSymbol (computed, ' /' , " \\ /" );
126+ computed = replaceSymbol (computed, ' *' , R"( [a-zA-Z0-9\/\.\-_:]*)" );
127+ computed = replaceSymbol (computed, ' +' , " ." );
114128 LOG (" Computed regex: %s" , computed.c_str ());
115129 return std::regex (computed);
116130}
117131
118- #endif // CAPIO_COMMON_FILESYSTEM_HPP
132+ #endif // CAPIO_COMMON_FILESYSTEM_HPP
0 commit comments