added mounting points

This commit is contained in:
georgemoralis 2023-11-03 18:03:48 +02:00
parent 1d76376d09
commit c41b773677
2 changed files with 60 additions and 2 deletions

View File

@ -1 +1,36 @@
namespace Core::FileSys {} #include "fs.h"
#include <algorithm>
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

View File

@ -1,4 +1,27 @@
#pragma once #pragma once
#include <mutex>
#include <string>
#include <vector>
namespace Core::FileSys { namespace Core::FileSys {
}
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<MntPair> m_mnt_pairs;
std::mutex m_mutex;
};
} // namespace Core::FileSys