Skip to content

Commit f0354b9

Browse files
committed
fix(cli): make package hash cleanup race-safe
2 parents 4bf68b1 + d1d6826 commit f0354b9

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎tests/PackageHashTests.cpp‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ static fs::path make_root()
4646
return root;
4747
}
4848

49+
static void cleanup_root(const fs::path &root) noexcept
50+
{
51+
// Git may still be finishing background maintenance when the test-owned
52+
// repository is torn down. Cleanup is best-effort and must not turn a
53+
// successful hash assertion into an exception from remove_all().
54+
std::error_code ec;
55+
fs::remove_all(root, ec);
56+
}
57+
4958
static fs::path make_git_repo(const fs::path &root)
5059
{
5160
fs::path repo = root / "repo";
@@ -73,7 +82,7 @@ static void test_reproducible_hash()
7382
assert(a.has_value());
7483
assert(b.has_value());
7584
assert(*a == *b);
76-
fs::remove_all(root);
85+
cleanup_root(root);
7786
}
7887

7988
static void test_git_metadata_and_untracked_files_are_excluded()
@@ -91,7 +100,7 @@ static void test_git_metadata_and_untracked_files_are_excluded()
91100
const auto after = vix::cli::util::sha256_package_directory(repo);
92101
assert(after.has_value());
93102
assert(*before == *after);
94-
fs::remove_all(root);
103+
cleanup_root(root);
95104
}
96105

97106
static void test_tracked_file_modification_changes_hash()
@@ -106,7 +115,7 @@ static void test_tracked_file_modification_changes_hash()
106115
const auto after = vix::cli::util::sha256_package_directory(repo);
107116
assert(after.has_value());
108117
assert(*before != *after);
109-
fs::remove_all(root);
118+
cleanup_root(root);
110119
}
111120

112121
int main()

0 commit comments

Comments
 (0)