Compare commits
2 commits
2b7e37e3b9
...
38a63f2e50
| Author | SHA1 | Date | |
|---|---|---|---|
| 38a63f2e50 | |||
|
|
5ac7077dd0 |
1 changed files with 10 additions and 2 deletions
|
|
@ -103,9 +103,13 @@ std::string FetchGit(const GitSource& source, const fs::path& cloneDir) {
|
|||
}
|
||||
}
|
||||
|
||||
// Random per-invocation tmp suffix so concurrent crafter-build processes
|
||||
// resolving to the same cache key don't share an in-flight `.tmp`
|
||||
// directory — git's pack tempfiles would get yanked when one process
|
||||
// removes or renames the dir out from under the other.
|
||||
std::random_device rd;
|
||||
fs::path tmpDir = cloneDir;
|
||||
tmpDir += ".tmp";
|
||||
if (fs::exists(tmpDir)) fs::remove_all(tmpDir);
|
||||
tmpDir += std::format(".tmp.{:08x}{:08x}", rd(), rd());
|
||||
|
||||
if (auto err = runGit(std::format("git clone --recursive {} {}", ShellQuote(source.url), ShellQuote(tmpDir.string())))) {
|
||||
if (fs::exists(tmpDir)) fs::remove_all(tmpDir);
|
||||
|
|
@ -128,6 +132,10 @@ std::string FetchGit(const GitSource& source, const fs::path& cloneDir) {
|
|||
fs::rename(tmpDir, cloneDir, ec);
|
||||
if (ec) {
|
||||
fs::remove_all(tmpDir);
|
||||
// If a concurrent build won the race, cloneDir now exists with the
|
||||
// same source revision (cache key includes url+branch+commit), so
|
||||
// discard our clone and reuse theirs.
|
||||
if (fs::exists(cloneDir)) return "";
|
||||
return std::format("rename {} -> {} failed: {}", tmpDir.string(), cloneDir.string(), ec.message());
|
||||
}
|
||||
return "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue