Skip to content

Commit e515fd3

Browse files
committed
Cleanup
1 parent b8c3040 commit e515fd3

81 files changed

Lines changed: 2289 additions & 1528 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/common/capio/env.hpp

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,36 @@
1212
#include "logger.hpp"
1313
#include "syscall.hpp"
1414

15-
inline const std::filesystem::path &get_capio_dir() {
15+
inline const std::filesystem::path& get_capio_dir()
16+
{
1617
static std::filesystem::path capio_dir{};
1718
START_LOG(capio_syscall(SYS_gettid), "call()");
1819
// TODO: if CAPIO_DIR is not set, it should be left as null
1920

20-
if (capio_dir.empty()) {
21-
const char *val = std::getenv("CAPIO_DIR");
22-
auto buf = std::unique_ptr<char[]>(new char[PATH_MAX]);
21+
if (capio_dir.empty())
22+
{
23+
const char* val = std::getenv("CAPIO_DIR");
24+
auto buf = std::unique_ptr<char[]>(new char[PATH_MAX]);
2325

24-
if (val == nullptr) {
26+
if (val == nullptr)
27+
{
2528
ERR_EXIT("Fatal: CAPIO_DIR not provided!");
26-
27-
} else {
28-
29-
const char *realpath_res = capio_realpath(val, buf.get());
30-
if (realpath_res == nullptr) {
29+
}
30+
else
31+
{
32+
const char* realpath_res = capio_realpath(val, buf.get());
33+
if (realpath_res == nullptr)
34+
{
3135
ERR_EXIT("error CAPIO_DIR: directory %s does not "
3236
"exist. [buf=%s]",
3337
val, buf.get());
3438
}
3539
}
3640
capio_dir = std::filesystem::path(buf.get());
37-
for (auto &forbidden_path : CAPIO_DIR_FORBIDDEN_PATHS) {
38-
if (capio_dir.native().rfind(forbidden_path, 0) == 0) {
41+
for (auto& forbidden_path : CAPIO_DIR_FORBIDDEN_PATHS)
42+
{
43+
if (capio_dir.native().rfind(forbidden_path, 0) == 0)
44+
{
3945
ERR_EXIT("CAPIO_DIR inside %s file system is not supported", forbidden_path.data());
4046
}
4147
}
@@ -45,20 +51,26 @@ inline const std::filesystem::path &get_capio_dir() {
4551
return capio_dir;
4652
}
4753

48-
inline const std::filesystem::path &get_capio_metadata_path() {
54+
inline const std::filesystem::path& get_capio_metadata_path()
55+
{
4956
static std::filesystem::path metadata_path{};
5057
START_LOG(capio_syscall(SYS_gettid), "call()");
51-
if (metadata_path.empty()) {
52-
const char *val = std::getenv("CAPIO_METADATA_DIR");
53-
auto buf = std::unique_ptr<char[]>(new char[PATH_MAX]);
58+
if (metadata_path.empty())
59+
{
60+
const char* val = std::getenv("CAPIO_METADATA_DIR");
61+
auto buf = std::unique_ptr<char[]>(new char[PATH_MAX]);
5462

55-
if (val == nullptr) {
63+
if (val == nullptr)
64+
{
5665
metadata_path = std::filesystem::current_path() / ".capio_metadata";
57-
} else {
66+
}
67+
else
68+
{
5869
metadata_path = std::filesystem::path(val) / ".capio_metadata";
5970
}
6071

61-
if (!std::filesystem::exists(metadata_path)) {
72+
if (!std::filesystem::exists(metadata_path))
73+
{
6274
std::filesystem::create_directories(metadata_path);
6375
}
6476
}
@@ -67,41 +79,53 @@ inline const std::filesystem::path &get_capio_metadata_path() {
6779
return metadata_path;
6880
}
6981

70-
inline int get_capio_log_level() {
82+
inline int get_capio_log_level()
83+
{
7184
static int level = -2;
72-
if (level == -2) {
73-
char *log_level = std::getenv("CAPIO_LOG_LEVEL");
74-
if (log_level == nullptr) {
85+
if (level == -2)
86+
{
87+
char* log_level = std::getenv("CAPIO_LOG_LEVEL");
88+
if (log_level == nullptr)
89+
{
7590
level = 0;
76-
} else {
91+
}
92+
else
93+
{
7794
auto [ptr, ec] = std::from_chars(log_level, log_level + strlen(log_level), level);
78-
if (ec != std::errc()) {
95+
if (ec != std::errc())
96+
{
7997
level = 0;
8098
}
8199
}
82100
}
83101
return level;
84102
}
85103

86-
inline std::string get_capio_workflow_name() {
104+
inline std::string get_capio_workflow_name()
105+
{
87106
static std::string name;
88107

89108
START_LOG(capio_syscall(SYS_gettid), "call()");
90109

91-
if (name.empty()) {
110+
if (name.empty())
111+
{
92112
LOG("name is empty");
93113
#ifdef __CAPIO_POSIX
94114
LOG("Fetching name from std::env");
95115
auto tmp = std::getenv("CAPIO_WORKFLOW_NAME");
96-
if (tmp != nullptr) {
116+
if (tmp != nullptr)
117+
{
97118
name = tmp;
98-
} else {
119+
}
120+
else
121+
{
99122
name = CAPIO_DEFAULT_WORKFLOW_NAME;
100123
}
101124
#else
102125
LOG("fetching name from workflow_name");
103126
name = capio_global_configuration->workflow_name;
104-
if (name.size() == 0) {
127+
if (name.size() == 0)
128+
{
105129
LOG("Falling back to default workflow name");
106130
name = CAPIO_DEFAULT_WORKFLOW_NAME;
107131
}
@@ -111,4 +135,4 @@ inline std::string get_capio_workflow_name() {
111135
return name;
112136
}
113137

114-
#endif // CAPIO_COMMON_ENV_HPP
138+
#endif // CAPIO_COMMON_ENV_HPP

src/common/capio/filesystem.hpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,71 @@
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

Comments
 (0)