diff --git a/src/core/file_sys/fs.cpp b/src/core/file_sys/fs.cpp index c7b0c57e..69bcbe47 100644 --- a/src/core/file_sys/fs.cpp +++ b/src/core/file_sys/fs.cpp @@ -1 +1,36 @@ -namespace Core::FileSys {} \ No newline at end of file +#include "fs.h" + +#include + +namespace Core::FileSys { +void MntPoints::mount(const std::string& host_folder, const std::string& guest_folder) { + std::unique_lock lock{m_mutex}; + + MntPair pair; + pair.host_path = host_folder; + pair.guest_path = guest_folder; + + m_mnt_pairs.push_back(pair); +} +void MntPoints::unmount(const std::string& path) {}//TODO! +void MntPoints::unmountAll() { + std::unique_lock lock{m_mutex}; + m_mnt_pairs.clear(); +} +std::string MntPoints::getHostDirectory(const std::string& guest_directory) { + std::unique_lock lock{m_mutex}; + for (auto& pair : m_mnt_pairs) { + if (pair.guest_path.starts_with(guest_directory)) { + return pair.host_path + guest_directory; + } + } + // hack for relative path , get app0 and assuming it goes from there + for (auto& pair : m_mnt_pairs) { + if (pair.guest_path.starts_with("/app0")) { + std::replace(pair.host_path.begin(), pair.host_path.end(), '\\', '/'); + return pair.host_path + guest_directory; + } + } + return ""; +} +} // namespace Core::FileSys \ No newline at end of file diff --git a/src/core/file_sys/fs.h b/src/core/file_sys/fs.h index 3ffad9c1..912d9825 100644 --- a/src/core/file_sys/fs.h +++ b/src/core/file_sys/fs.h @@ -1,4 +1,27 @@ #pragma once +#include +#include +#include namespace Core::FileSys { -} \ No newline at end of file + +class MntPoints { + public: + struct MntPair { + std::string host_path; + std::string guest_path; // e.g /app0/ + }; + + MntPoints() {} + virtual ~MntPoints() {} + void mount(const std::string& host_folder, const std::string& guest_folder); + void unmount(const std::string& path); + void unmountAll(); + std::string getHostDirectory(const std::string& guest_directory); + + private: + std::vector m_mnt_pairs; + std::mutex m_mutex; +}; + +} // namespace Core::FileSys \ No newline at end of file