Verified Commit 882baec4 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Store mountdir as splitted string components

parent 0ab63945
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#define IFS_PATH_UTIL_HPP

#include <string>
#include <vector>

#define PATH_MAX_LEN 4096 // 4k chars

@@ -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
+5 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include <spdlog/spdlog.h>
#include <map>
#include <memory>
#include <vector>
#include <string>

/* Forward declarations */
@@ -46,6 +47,7 @@ class PreloadContext {
    std::shared_ptr<FsConfig> fs_conf_;

    std::string cwd_;
    std::vector<std::string> mountdir_components_;
    std::string mountdir_;
    std::string daemon_addr_str_;
    bool initialized_;
@@ -63,13 +65,14 @@ 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 daemon_addr_str(const std::string& path);
    const std::string& daemon_addr_str() const;

    void cwd(const std::string& path);
    std::string cwd() const;
    const std::string& cwd() const;

    bool relativize_path(std::string& path) const;

+15 −0
Original line number Diff line number Diff line
@@ -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.
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,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;
}