MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / scratch_dir

Function scratch_dir

tests/support/scratch_dir.h:48–63  ·  view source on GitHub ↗

Fresh, uniquely named directory for one test binary's temp files: portable mkdtemp semantics -- unpredictable name, atomic create that fails on a squatted name, owner-only permissions. Base comes from gtest's TempDir(), which honors TEST_TMPDIR when the CI runner provides a per-test private dir.

Source from the content-addressed store, hash-verified

46// gtest's TempDir(), which honors TEST_TMPDIR when the CI runner
47// provides a per-test private dir.
48inline std::filesystem::path scratch_dir() {
49 namespace fs = std::filesystem;
50 const fs::path base{::testing::TempDir()};
51 std::random_device rd;
52 for (int attempt = 0; attempt < 16; ++attempt) {
53 const std::string name =
54 std::format("oid_scratch_{:x}{:x}", rd(), rd());
55 const fs::path dir = base / name;
56 if (fs::create_directory(dir)) { // atomic; false if name taken
57 fs::permissions(
58 dir, fs::perms::owner_all, fs::perm_options::replace);
59 return dir;
60 }
61 }
62 throw ScratchDirError{"scratch_dir: could not create a unique dir"};
63}
64
65} // namespace oid::test
66

Callers 4

TESTFunction · 0.85
temp_fileFunction · 0.85
TESTFunction · 0.85
TESTFunction · 0.85

Calls

no outgoing calls

Tested by 4

TESTFunction · 0.68
temp_fileFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68