From 8735e66fe9e0668087af9002d6eb2e838d3d4142 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 Aug 2025 12:13:27 +0000 Subject: [PATCH 1/5] Initial plan From 9177d50b4abca343cbb8891f4121e1116e5db333 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 Aug 2025 12:30:23 +0000 Subject: [PATCH 2/5] Fix: Only create mismatch directory when files are actually written Co-authored-by: mortenvp <1279584+mortenvp@users.noreply.github.com> --- src/datarecorder/datarecorder.hpp | 21 ++++++++++------ test/src/test_datarecorder.cpp | 42 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/datarecorder/datarecorder.hpp b/src/datarecorder/datarecorder.hpp index e60e327..309f1de 100644 --- a/src/datarecorder/datarecorder.hpp +++ b/src/datarecorder/datarecorder.hpp @@ -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"); @@ -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); @@ -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"}); diff --git a/test/src/test_datarecorder.cpp b/test/src/test_datarecorder.cpp index 750fe74..a1580b2 100644 --- a/test/src/test_datarecorder.cpp +++ b/test/src/test_datarecorder.cpp @@ -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); +} From 9d61f417b9887cdbef0ebfb6952ee1f053f6aeb9 Mon Sep 17 00:00:00 2001 From: Jeppe Axelsen Date: Thu, 28 Aug 2025 10:31:11 -0100 Subject: [PATCH 3/5] ran --lock-versions --- lock_version_resolve.json | 107 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 lock_version_resolve.json diff --git a/lock_version_resolve.json b/lock_version_resolve.json new file mode 100644 index 0000000..afae662 --- /dev/null +++ b/lock_version_resolve.json @@ -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" + } +} \ No newline at end of file From 2c8c55e83c67ab055e62334d30d6ec32e3e6011b Mon Sep 17 00:00:00 2001 From: Jeppe Axelsen Date: Thu, 28 Aug 2025 10:31:35 -0100 Subject: [PATCH 4/5] clang-format --- src/datarecorder/datarecorder.hpp | 2 +- ...arecorder_mismatch_directory_only_created_when_needed.data | 1 + test/src/test_datarecorder.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 test/recordings/datarecorder_mismatch_directory_only_created_when_needed.data diff --git a/src/datarecorder/datarecorder.hpp b/src/datarecorder/datarecorder.hpp index 309f1de..96554af 100644 --- a/src/datarecorder/datarecorder.hpp +++ b/src/datarecorder/datarecorder.hpp @@ -294,7 +294,7 @@ class datarecorder { std::error_code ec; bool created = std::filesystem::create_directories(parent_dir, ec); - VERIFY(created || std::filesystem::exists(parent_dir), + VERIFY(created || std::filesystem::exists(parent_dir), "Could not create parent directories", ec, parent_dir); } diff --git a/test/recordings/datarecorder_mismatch_directory_only_created_when_needed.data b/test/recordings/datarecorder_mismatch_directory_only_created_when_needed.data new file mode 100644 index 0000000..a49b13a --- /dev/null +++ b/test/recordings/datarecorder_mismatch_directory_only_created_when_needed.data @@ -0,0 +1 @@ +test data for directory creation \ No newline at end of file diff --git a/test/src/test_datarecorder.cpp b/test/src/test_datarecorder.cpp index a1580b2..b951fc1 100644 --- a/test/src/test_datarecorder.cpp +++ b/test/src/test_datarecorder.cpp @@ -41,7 +41,7 @@ TEST(datarecorder, mismatch_directory_only_created_when_needed) int initial_count = 0; for (const auto& entry : std::filesystem::directory_iterator(tmp_dir)) { - if (entry.is_directory() && + if (entry.is_directory() && entry.path().filename().string().find("cppmismatch-") == 0) { initial_count++; @@ -56,7 +56,7 @@ TEST(datarecorder, mismatch_directory_only_created_when_needed) int final_count = 0; for (const auto& entry : std::filesystem::directory_iterator(tmp_dir)) { - if (entry.is_directory() && + if (entry.is_directory() && entry.path().filename().string().find("cppmismatch-") == 0) { final_count++; From 95d5fb50746dcb407dc13393e70a2aadf2495e52 Mon Sep 17 00:00:00 2001 From: Jeppe Axelsen Date: Thu, 28 Aug 2025 12:05:11 -0100 Subject: [PATCH 5/5] update newst.rst --- NEWS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.rst b/NEWS.rst index f17edc4..6a525d1 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -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 -----