diff options
Diffstat (limited to 'src/buildtool/file_system')
-rw-r--r-- | src/buildtool/file_system/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 13 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 5 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index b368e5b4..427e7628 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -108,6 +108,7 @@ , ["src/utils/cpp", "path"] , ["src/utils/cpp", "hex_string"] , ["src/utils/cpp", "gsl"] + , ["src/utils/cpp", "tmp_dir"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/common", "common"] ] 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; } diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 09e65402..7d0428d0 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -272,13 +272,10 @@ class GitRepo { /// \brief Fetch from given local repository via a temporary location. Uses /// tmp dir to fetch asynchronously using libgit2. - /// Caller needs to make sure the temporary directory exists and that the - /// given path is thread- and process-safe! /// Uses either a given branch, or fetches all (with base refspecs). /// Returns a success flag. /// It guarantees the logger is called exactly once with fatal if failure. [[nodiscard]] auto LocalFetchViaTmpRepo( - std::filesystem::path const& tmp_dir, std::string const& repo_path, std::optional<std::string> const& branch, anon_logger_ptr const& logger) noexcept -> bool; @@ -344,4 +341,4 @@ class GitRepo { std::vector<std::string> const& string_list) noexcept; }; -#endif // INCLUDED_SRC_BUILDTOOL_FILE_SYSTEM_GIT_REPO_HPP
\ No newline at end of file +#endif // INCLUDED_SRC_BUILDTOOL_FILE_SYSTEM_GIT_REPO_HPP |