Loading ifs/include/global/path_util.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #define IFS_PATH_UTIL_HPP #include <string> #include <vector> #define PATH_MAX_LEN 4096 // 4k chars Loading @@ -12,5 +13,6 @@ bool has_trailing_slash(const std::string& path); std::string path_to_relative(const std::string& root_path, const std::string& complete_path); std::string dirname(const std::string& path); std::string get_current_working_dir(); std::vector<std::string> split_path(const std::string& path); #endif //IFS_PATH_UTIL_HPP ifs/include/preload/preload_context.hpp +5 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ #include <extern/spdlog/spdlog.h> #include <memory> #include <vector> #include <string> /* Forward declarations */ Loading Loading @@ -45,6 +46,7 @@ class PreloadContext { std::shared_ptr<FsConfig> fs_conf_; std::string cwd_; std::vector<std::string> mountdir_components_; std::string mountdir_; bool initialized_; Loading @@ -61,10 +63,11 @@ class PreloadContext { std::shared_ptr<spdlog::logger> log() const; void mountdir(const std::string& path); std::string mountdir() const; const std::string& mountdir() const; const std::vector<std::string>& mountdir_components() const; void cwd(const std::string& path); std::string cwd() const; const std::string& cwd() const; bool relativize_path(std::string& path) const; Loading ifs/src/global/path_util.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,21 @@ bool has_trailing_slash(const std::string& path) { return path.back() == PSP; } std::vector<std::string> split_path(const std::string& path) { std::vector<std::string> tokens; size_t start = std::string::npos; size_t end = (path.front() != PSP)? 0 : 1; while(end != std::string::npos && end < path.size()) { start = end; end = path.find(PSP, start); tokens.push_back(path.substr(start, end - start)); if(end != std::string::npos) { ++end; } } return tokens; } /* Make an absolute path relative to a root path * * Convert @absolute_path into a relative one with respect to the given @root_path. Loading ifs/src/preload/preload_context.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ std::shared_ptr<spdlog::logger> PreloadContext::log() const { void PreloadContext::mountdir(const std::string& path) { assert(is_absolute_path(path)); mountdir_components_ = split_path(path); mountdir_ = path; } Loading Loading
ifs/include/global/path_util.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #define IFS_PATH_UTIL_HPP #include <string> #include <vector> #define PATH_MAX_LEN 4096 // 4k chars Loading @@ -12,5 +13,6 @@ bool has_trailing_slash(const std::string& path); std::string path_to_relative(const std::string& root_path, const std::string& complete_path); std::string dirname(const std::string& path); std::string get_current_working_dir(); std::vector<std::string> split_path(const std::string& path); #endif //IFS_PATH_UTIL_HPP
ifs/include/preload/preload_context.hpp +5 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ #include <extern/spdlog/spdlog.h> #include <memory> #include <vector> #include <string> /* Forward declarations */ Loading Loading @@ -45,6 +46,7 @@ class PreloadContext { std::shared_ptr<FsConfig> fs_conf_; std::string cwd_; std::vector<std::string> mountdir_components_; std::string mountdir_; bool initialized_; Loading @@ -61,10 +63,11 @@ class PreloadContext { std::shared_ptr<spdlog::logger> log() const; void mountdir(const std::string& path); std::string mountdir() const; const std::string& mountdir() const; const std::vector<std::string>& mountdir_components() const; void cwd(const std::string& path); std::string cwd() const; const std::string& cwd() const; bool relativize_path(std::string& path) const; Loading
ifs/src/global/path_util.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,21 @@ bool has_trailing_slash(const std::string& path) { return path.back() == PSP; } std::vector<std::string> split_path(const std::string& path) { std::vector<std::string> tokens; size_t start = std::string::npos; size_t end = (path.front() != PSP)? 0 : 1; while(end != std::string::npos && end < path.size()) { start = end; end = path.find(PSP, start); tokens.push_back(path.substr(start, end - start)); if(end != std::string::npos) { ++end; } } return tokens; } /* Make an absolute path relative to a root path * * Convert @absolute_path into a relative one with respect to the given @root_path. Loading
ifs/src/preload/preload_context.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ std::shared_ptr<spdlog::logger> PreloadContext::log() const { void PreloadContext::mountdir(const std::string& path) { assert(is_absolute_path(path)); mountdir_components_ = split_path(path); mountdir_ = path; } Loading