File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88#include < cstdio>
99#include < cstring>
10+ #include < fcntl.h>
1011#include < filesystem>
12+ #include < unistd.h>
1113#include < vector>
1214
1315#include " catalog/catalog.hpp"
@@ -239,10 +241,14 @@ TEST(CatalogCoverageTests, SaveAndLoad) {
239241 std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
240242 catalog->create_table (" persisted_table" , cols);
241243
242- // Use unique temp path to avoid collisions in parallel runs
243- static int test_counter = 0 ;
244- std::string temp_filename = " /tmp/test_catalog_" + std::to_string (++test_counter) + " .bin" ;
245- std::filesystem::path temp_path (temp_filename);
244+ // Use mkstemp to create a unique temp file atomically
245+ std::string temp_template = " /tmp/test_catalog_XXXXXX.bin" ;
246+ std::vector<char > temp_path_vec (temp_template.begin (), temp_template.end ());
247+ temp_path_vec.push_back (' \0 ' ); // null-terminate for mkstemp
248+ int fd = mkstemp (temp_path_vec.data ());
249+ ASSERT_NE (fd, -1 );
250+ std::filesystem::path temp_path (temp_path_vec.data ());
251+ close (fd); // Close the file descriptor, we only need the path
246252
247253 // Save catalog - should succeed
248254 ASSERT_TRUE (catalog->save (temp_path.string ()));
You can’t perform that action at this time.
0 commit comments