diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2024-02-23 18:51:51 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2024-03-08 14:16:45 +0100 |
commit | 2ebf355989eb92ac9967eceee0af14d39477afe0 (patch) | |
tree | db993f8df39eb05b625b2c4590f1e5696b2e7b04 /src/buildtool/file_system/git_repo.cpp | |
parent | c512ae174920ada425e2b33d0fea24891d6305bd (diff) | |
download | justbuild-2ebf355989eb92ac9967eceee0af14d39477afe0.tar.gz |
just-mr: Fix shell out execution
... by avoiding reusing temp dirs for execute. While we are
at it, also refactor LocalFetchViaTmpRepo() to create its
own empty temp dirs, that cannot be reused by the caller.
Diffstat (limited to 'src/buildtool/file_system/git_repo.cpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 72f85f6a..2022d0b1 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -23,6 +23,7 @@ #include "src/utils/cpp/gsl.hpp" #include "src/utils/cpp/hex_string.hpp" #include "src/utils/cpp/path.hpp" +#include "src/utils/cpp/tmp_dir.hpp" extern "C" { #include <git2.h> @@ -1541,8 +1542,7 @@ auto GitRepo::GetObjectByPathFromTree(std::string const& tree_id, #endif // BOOTSTRAP_BUILD_TOOL } -auto GitRepo::LocalFetchViaTmpRepo(std::filesystem::path const& tmp_dir, - std::string const& repo_path, +auto GitRepo::LocalFetchViaTmpRepo(std::string const& repo_path, std::optional<std::string> const& branch, anon_logger_ptr const& logger) noexcept -> bool { @@ -1555,10 +1555,17 @@ auto GitRepo::LocalFetchViaTmpRepo(std::filesystem::path const& tmp_dir, Logger::Log(LogLevel::Debug, "Branch local fetch called on a real repository"); } + auto tmp_dir = TmpDir::Create("local_fetch"); + if (not tmp_dir) { + (*logger)("Failed to create temp dir for Git repository", + /*fatal=*/true); + return false; + } + auto const& tmp_path = tmp_dir->GetPath(); // create the temporary real repository // it can be bare, as the refspecs for this fetch will be given // explicitly. - auto tmp_repo = GitRepo::InitAndOpen(tmp_dir, /*is_bare=*/true); + auto tmp_repo = GitRepo::InitAndOpen(tmp_path, /*is_bare=*/true); if (tmp_repo == std::nullopt) { return false; } |