diff --git a/src/fs.h b/src/fs.h --- a/src/fs.h +++ b/src/fs.h @@ -246,7 +246,9 @@ typedef fs::ifstream ifstream; typedef fs::ofstream ofstream; #endif // WIN32 && __GLIBCXX__ -}; // namespace fsbridge + +fs::path GetTempDirectoryPath(); +}; // namespace fsbridge // Disallow path operator<< formatting in tinyformat to avoid locale-dependent // encoding on windows. diff --git a/src/fs.cpp b/src/fs.cpp --- a/src/fs.cpp +++ b/src/fs.cpp @@ -265,4 +265,17 @@ #endif // __GLIBCXX__ #endif // WIN32 +fs::path GetTempDirectoryPath() { +#ifndef WIN32 + return fs::temp_directory_path(); +#else + wchar_t dirPathWchars[MAX_PATH]; + GetTempPathW(MAX_PATH, dirPathWchars); + std::wstring dirPathWstring(dirPathWchars); + return fs::PathFromString( + std::wstring_convert>().to_bytes( + dirPathWstring)); +#endif +} + } // namespace fsbridge diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -103,7 +103,8 @@ BasicTestingSetup::BasicTestingSetup( const std::string &chainName, const std::vector &extra_args) - : m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / + : m_path_root{fsbridge::GetTempDirectoryPath() / + "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()}, m_args{} { // clang-format off