Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ every change, see the Git log.

Latest
------
* tbd
* Patch: Stopped the creation of mismatch dir when no files will be written to it.

1.0.1
-----
Expand Down
107 changes: 107 additions & 0 deletions lock_version_resolve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"abacus": {
"commit_id": "964e2035583b77d8bdb4eb30f1e95db0ba2577a4",
"resolver_info": "8.0.0",
"sha1": "81811cbb1887f87ef86cd7b1022280663b55c8a9"
},
"abseil": {
"commit_id": "d6a9562e974b409cbc8d1e44b40f713a80ff7d6c",
"resolver_info": "1.0.2",
"sha1": "fbbadb116d16047bce4ad8e1726804a01eb8e98a"
},
"abseil-source": {
"commit_id": "bc257a88f7c1939f24e0379f14a3589e926c950c",
"resolver_info": "20250512.0",
"sha1": "8e016b57dd5361fe7f66ae47f3df42ab634321c5"
},
"bourne": {
"commit_id": "cf4fed3ea15525a6608722db56f10ff4314c2354",
"resolver_info": "11.0.0",
"sha1": "f705097630cc09ecd747eaf3b5eef8966cfa4fba"
},
"endian": {
"commit_id": "b3702d8d134a06b5829119934718a75f4e171699",
"resolver_info": "14.0.0",
"sha1": "ebfaeeec96922b484b061fd860c46ee1264eca21"
},
"expected": {
"commit_id": "e84368a61a223dd0fb3ad60d6e6791a3ffc199f7",
"resolver_info": "2.0.0",
"sha1": "2760f759e9baeaace1f61449d61c8197d1ffb77d"
},
"expected-source": {
"commit_id": "292eff8bd8ee230a7df1d6a1c00c4ea0eb2f0362",
"resolver_info": "v1.1.0",
"sha1": "5078750ed20c6d6323d27ed96fb2ddebc43bb247"
},
"fmt": {
"commit_id": "5d5eb0f166979fa523704114620a40b3e9e6bb08",
"resolver_info": "5.0.0",
"sha1": "160978c7e6571cc06d6c8a590e5e0c4f3c826fba"
},
"fmt-source": {
"commit_id": "0c9fce2ffefecfdce794e1859584e25877b7b592",
"resolver_info": "11.0.2",
"sha1": "f39ff778b3283f543cdfc9b1662ec101c453efce"
},
"gtest": {
"commit_id": "8e1f80ae8618fdba4389f1b56c811ea7241569d1",
"resolver_info": "6.0.2",
"sha1": "44c35f8798a738692c902fe2b67dc0cb76a1df53"
},
"gtest-source": {
"commit_id": "52eb8108c5bdec04579160ae17225d66034bd723",
"resolver_info": "v1.17.0",
"sha1": "8600eafa3daedc694d3115677da0dda3af6a8633"
},
"libassert-source": {
"commit_id": "60667829264ae01241257df7f1c7d6dba668eb9d",
"resolver_info": "v2.1.5",
"sha1": "650d881b8cb6cc1adf354d47d6353db6ec4fd6a5"
},
"platform": {
"commit_id": "7740600dfa6c8800819737dd85fb89c16c1c0c01",
"resolver_info": "6.0.0",
"sha1": "7a014ba5a95cf7f0193213e95d3d2d8fcfa313b7"
},
"poke": {
"commit_id": "97669413ea61728f6c0971558e66ae7d383ba85a",
"resolver_info": "16.0.2",
"sha1": "779b0b9b6ef137a2e7672d88c582136ee28c0610"
},
"protobuf": {
"commit_id": "a32b1956282c0e89a8e24cecfcb1e46606071750",
"resolver_info": "3.0.0",
"sha1": "4423b2b25fe48344a027237e34317898651b99cf"
},
"protobuf-source": {
"commit_id": "3d4adad5c4c4e6a6f9f038769b8c90716065b0e4",
"resolver_info": "v31.0",
"sha1": "93bde6d21d12c24893dc159f0a51bbb717118abb"
},
"source_location": {
"commit_id": "c2dbc1e904f3900e881c98e0569d23e044a48246",
"resolver_info": "2.0.0",
"sha1": "1a08be8297afc59e088f710950b95ec073f032df"
},
"source_location-source": {
"commit_id": "e3849453a302b52305a146eaa3809bd797679233",
"resolver_info": "e384945",
"sha1": "67edfd49ad879868b7d6a48b4e72d7f0cd969b46"
},
"toolchains": {
"commit_id": "d771e98c84304735f43db13d50edffd8e7d5a9d6",
"resolver_info": "1.0.5",
"sha1": "443cb23b0570dffd39283d8679ec393ed809302f"
},
"verify": {
"commit_id": "7f7c4b0d66d6d0036aa84ccab16fae2b1c8c207b",
"resolver_info": "6.0.2",
"sha1": "fed379602b6ea7bd611fc249daffa11b9e593800"
},
"zlib-source": {
"commit_id": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf",
"resolver_info": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf",
"sha1": "33283130debb8bf95a98929ff6cadd5bd9cb6a92"
}
}
21 changes: 13 additions & 8 deletions src/datarecorder/datarecorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class datarecorder
}
}

auto determine_mismatch_dir() -> std::filesystem::path
auto determine_mismatch_path() -> std::filesystem::path
{
VERIFY(m_recording_dir, "Recording dir must not be empty");

Expand All @@ -282,17 +282,22 @@ class datarecorder
mismatch_dir = tmp_dir / ("cppmismatch-" + std::to_string(i));
}

// Create the directory
std::error_code ec;
bool created = std::filesystem::create_directory(mismatch_dir, ec);

VERIFY(created, "Could not create directory", ec);

// Return the path without creating the directory
return mismatch_dir;
}

void write_data(const std::filesystem::path& path, const std::string& data)
{
// Create parent directories if they don't exist
std::filesystem::path parent_dir = path.parent_path();
if (!parent_dir.empty() && !std::filesystem::exists(parent_dir))
{
std::error_code ec;
bool created = std::filesystem::create_directories(parent_dir, ec);
VERIFY(created || std::filesystem::exists(parent_dir),
"Could not create parent directories", ec, parent_dir);
}

std::ofstream file(path, std::ios::out | std::ios::trunc);
VERIFY(file.is_open(), "Could not open file for writing", errno, path);

Expand Down Expand Up @@ -326,7 +331,7 @@ class datarecorder
if (data != recording_data)
{
// If it exists we check for a mismatch
std::filesystem::path mismatch_dir = determine_mismatch_dir();
std::filesystem::path mismatch_dir = determine_mismatch_path();

m_monitor.log(poke::log_level::debug,
poke::log::str{"message", "Mismatch found"});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test data for directory creation
42 changes: 42 additions & 0 deletions test/src/test_datarecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,45 @@ TEST(datarecorder, record_string)
auto mismatch_result = recorder.record(data);
EXPECT_FALSE(mismatch_result);
}

TEST(datarecorder, mismatch_directory_only_created_when_needed)
{
// Test that mismatch directories are not created unnecessarily
datarecorder::datarecorder recorder;
recorder.set_recording_dir("test/recordings");

// Record initial data
std::string data = "test data for directory creation";
auto result = recorder.record(data);
EXPECT_TRUE(result);

// Count existing mismatch directories before test
std::filesystem::path tmp_dir = std::filesystem::temp_directory_path();
int initial_count = 0;
for (const auto& entry : std::filesystem::directory_iterator(tmp_dir))
{
if (entry.is_directory() &&
entry.path().filename().string().find("cppmismatch-") == 0)
{
initial_count++;
}
}

// Record the same data again (no mismatch, no directory should be created)
result = recorder.record(data);
EXPECT_TRUE(result);

// Count directories after test
int final_count = 0;
for (const auto& entry : std::filesystem::directory_iterator(tmp_dir))
{
if (entry.is_directory() &&
entry.path().filename().string().find("cppmismatch-") == 0)
{
final_count++;
}
}

// No new directories should have been created
EXPECT_EQ(initial_count, final_count);
}