summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-06-02 13:32:29 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-06-05 12:41:38 +0200
commit06bb4f11a21aae5713d75b496145f6621302ae3a (patch)
tree3ec94491c304300af84f2f2e600de4a068ad81f1
parent0039bf3dabf0068870e59acfa49683007d378c53 (diff)
downloadjustbuild-06bb4f11a21aae5713d75b496145f6621302ae3a.tar.gz
git cas: only compute absolute path if not absolute already
... and in this way, continue to work correctly in the absence of a current working directory.
-rw-r--r--src/buildtool/file_system/TARGETS1
-rw-r--r--src/buildtool/file_system/git_cas.cpp19
2 files changed, 17 insertions, 3 deletions
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS
index 1af5dea8..26bb3933 100644
--- a/src/buildtool/file_system/TARGETS
+++ b/src/buildtool/file_system/TARGETS
@@ -57,6 +57,7 @@
, "private-deps":
[ ["src/buildtool/logging", "logging"]
, ["src/utils/cpp", "hex_string"]
+ , ["src/utils/cpp", "path"]
, ["", "libgit2"]
]
}
diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp
index f134a894..7bddf6b3 100644
--- a/src/buildtool/file_system/git_cas.cpp
+++ b/src/buildtool/file_system/git_cas.cpp
@@ -21,6 +21,7 @@
#include "gsl/gsl"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/hex_string.hpp"
+#include "src/utils/cpp/path.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
@@ -155,9 +156,21 @@ auto GitCAS::OpenODB(std::filesystem::path const& repo_path) noexcept -> bool {
git_odb* odb_ptr{nullptr};
git_repository_odb(&odb_ptr, repo);
odb_.reset(odb_ptr); // retain odb pointer
- // set root
- git_path_ = std::filesystem::weakly_canonical(std::filesystem::absolute(
- std::filesystem::path(git_repository_path(repo))));
+ // set root
+ std::filesystem::path git_path =
+ ToNormalPath(git_repository_path(repo));
+ if (not git_path.is_absolute()) {
+ try {
+ git_path = std::filesystem::absolute(git_path);
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Error,
+ "Failed to obtain absolute path for {}: {}",
+ git_path.string(),
+ e.what());
+ return false;
+ }
+ }
+ git_path_ = git_path;
// release resources
git_repository_free(repo);
}