From ed9bfe29a1d54a6dca1fa85853457c56108a6183 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 27 Mar 2023 18:15:08 +0200 Subject: 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. --- src/buildtool/file_system/git_cas.hpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/buildtool/file_system/git_cas.hpp') 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 #include #include +#include #include #include @@ -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; -- cgit v1.2.3