core: file_sys: fix for racing in fs mount

This commit is contained in:
psucien 2024-09-19 21:42:19 +02:00
parent 07de1ee977
commit 7b8f0d2a19
2 changed files with 2 additions and 0 deletions

View file

@ -15,6 +15,7 @@ void MntPoints::Mount(const std::filesystem::path& host_folder, const std::strin
}
void MntPoints::Unmount(const std::filesystem::path& host_folder, const std::string& guest_folder) {
std::scoped_lock lock{m_mutex};
auto it = std::remove_if(m_mnt_pairs.begin(), m_mnt_pairs.end(),
[&](const MntPair& pair) { return pair.mount == guest_folder; });
m_mnt_pairs.erase(it, m_mnt_pairs.end());

View file

@ -34,6 +34,7 @@ public:
std::filesystem::path GetHostPath(std::string_view guest_directory);
const MntPair* GetMount(const std::string& guest_path) {
std::scoped_lock lock{m_mutex};
const auto it = std::ranges::find_if(
m_mnt_pairs, [&](const auto& mount) { return guest_path.starts_with(mount.mount); });
return it == m_mnt_pairs.end() ? nullptr : &*it;