summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_cas.hpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-03-27 18:15:08 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-03-30 13:45:00 +0200
commited9bfe29a1d54a6dca1fa85853457c56108a6183 (patch)
treedcfa02e41e34cb727855e2d8cdbf0bcb9bbb2fba /src/buildtool/file_system/git_cas.hpp
parent0c90ad4bf580a385aa7056298452980b5f8ceb83 (diff)
downloadjustbuild-ed9bfe29a1d54a6dca1fa85853457c56108a6183.tar.gz
GitRepo: Guard fake repository odb wrapping
In the current libgit2 implementation, a fake repository wrapped around an existing odb is being registered as owner the same way as a normal repository object. Therefore, one has to guard both the creation and destruction of the fake repository against all other git operations that might access the internal cache during this transfer of ownership.
Diffstat (limited to 'src/buildtool/file_system/git_cas.hpp')
-rw-r--r--src/buildtool/file_system/git_cas.hpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/buildtool/file_system/git_cas.hpp b/src/buildtool/file_system/git_cas.hpp
index 44b61cb4..f95cb403 100644
--- a/src/buildtool/file_system/git_cas.hpp
+++ b/src/buildtool/file_system/git_cas.hpp
@@ -18,6 +18,7 @@
#include <filesystem>
#include <memory>
#include <optional>
+#include <shared_mutex>
#include <unordered_map>
#include <vector>
@@ -67,6 +68,11 @@ class GitCAS {
// git folder path of repo
std::filesystem::path git_path_{};
+ // mutex to guard odb while setting up a "fake" repository; it needs to be
+ // uniquely owned while wrapping the odb, but then git operations are free
+ // to share it.
+ mutable std::shared_mutex mutex_{};
+
[[nodiscard]] auto OpenODB(std::filesystem::path const& repo_path) noexcept
-> bool;