summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/git_cas.cpp
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.cpp
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.cpp')
-rw-r--r--src/buildtool/file_system/git_cas.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp
index 2a4a7142..1f8525fe 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -81,12 +81,15 @@ auto GitCAS::ReadObject(std::string const& id, bool is_hex_id) const noexcept
}
git_odb_object* obj = nullptr;
- if (git_odb_read(&obj, odb_.get(), &oid.value()) != 0) {
- Logger::Log(LogLevel::Error,
- "reading git object {} from database failed with:\n{}",
- is_hex_id ? id : ToHexString(id),
- GitLastError());
- return std::nullopt;
+ {
+ std::shared_lock lock{mutex_};
+ if (git_odb_read(&obj, odb_.get(), &oid.value()) != 0) {
+ Logger::Log(LogLevel::Error,
+ "reading git object {} from database failed with:\n{}",
+ is_hex_id ? id : ToHexString(id),
+ GitLastError());
+ return std::nullopt;
+ }
}
std::string data(static_cast<char const*>(git_odb_object_data(obj)),
@@ -111,13 +114,16 @@ auto GitCAS::ReadHeader(std::string const& id, bool is_hex_id) const noexcept
std::size_t size{};
git_object_t type{};
- if (git_odb_read_header(&size, &type, odb_.get(), &oid.value()) != 0) {
- Logger::Log(LogLevel::Error,
- "reading git object header {} from database failed "
- "with:\n{}",
- is_hex_id ? id : ToHexString(id),
- GitLastError());
- return std::nullopt;
+ {
+ std::shared_lock lock{mutex_};
+ if (git_odb_read_header(&size, &type, odb_.get(), &oid.value()) != 0) {
+ Logger::Log(LogLevel::Error,
+ "reading git object header {} from database failed "
+ "with:\n{}",
+ is_hex_id ? id : ToHexString(id),
+ GitLastError());
+ return std::nullopt;
+ }
}
if (auto obj_type = GitTypeToObjectType(type)) {