From 7b8f0d2a19fd430b3760f3deb0a08cbf6b6ba148 Mon Sep 17 00:00:00 2001 From: psucien Date: Thu, 19 Sep 2024 21:42:19 +0200 Subject: [PATCH] core: file_sys: fix for racing in fs mount --- src/core/file_sys/fs.cpp | 1 + src/core/file_sys/fs.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/core/file_sys/fs.cpp b/src/core/file_sys/fs.cpp index 199e42a0..da631d63 100644 --- a/src/core/file_sys/fs.cpp +++ b/src/core/file_sys/fs.cpp @@ -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()); diff --git a/src/core/file_sys/fs.h b/src/core/file_sys/fs.h index 2c55b051..ddd02f53 100644 --- a/src/core/file_sys/fs.h +++ b/src/core/file_sys/fs.h @@ -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;