#include #include #include #include #include PreloadContext::PreloadContext(): ofm_(std::make_shared()), fs_conf_(std::make_shared()) {} void PreloadContext::log(std::shared_ptr logger) { log_ = logger; } std::shared_ptr PreloadContext::log() const { return log_; } void PreloadContext::mountdir(const std::string& path) { assert(is_absolute_path(path)); assert(!has_trailing_slash(path)); mountdir_components_ = split_path(path); mountdir_ = path; } const std::string& PreloadContext::mountdir() const { return mountdir_; } void PreloadContext::daemon_addr_str(const std::string& addr) { assert(!addr.empty()); daemon_addr_str_ = addr; } const std::string& PreloadContext::daemon_addr_str() const { assert(!daemon_addr_str_.empty()); return daemon_addr_str_; } const std::vector& PreloadContext::mountdir_components() const { return mountdir_components_; } void PreloadContext::cwd(const std::string& path) { log_->debug("Setting CWD to '{}'", path); cwd_ = path; } const std::string& PreloadContext::cwd() const { return cwd_; } bool PreloadContext::relativize_path(const char * raw_path, std::string& relative_path) const { // Relativize path should be called only after the library constructor has been executed assert(initialized_); // If we run the constructor we also already setup the mountdir assert(!mountdir_.empty()); if(raw_path == nullptr || raw_path[0] == '\0') { return false; } std::string path; if(raw_path[0] != PSP) { /* Path is not absolute, we need to prepend CWD; * First reserve enough space to minimize memory copy */ path = prepend_path(cwd_, raw_path); } else { path = raw_path; } return resolve_path(path, relative_path); } const std::shared_ptr& PreloadContext::file_map() const { return ofm_; } void PreloadContext::distributor(std::shared_ptr d) { distributor_ = d; } std::shared_ptr PreloadContext::distributor() const { return distributor_; } const std::shared_ptr& PreloadContext::fs_conf() const { return fs_conf_; } void PreloadContext::initialized(const bool& flag) { initialized_ = flag; } bool PreloadContext::initialized() const { return initialized_; }