From d4999d40b9bd04dc20111aaaa6ed2d3db1a5caf9 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 13 Feb 2022 17:30:21 +0200 Subject: util: Revert back MoveFileExW call for MinGW-w64 --- src/util/system.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/util/system.cpp b/src/util/system.cpp index 5cef2be07a..69811a751b 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1062,9 +1062,20 @@ void ArgsManager::LogArgs() const bool RenameOver(fs::path src, fs::path dest) { +#ifdef __MINGW64__ + // This is a workaround for a bug in libstdc++ which + // implements std::filesystem::rename with _wrename function. + // This bug has been fixed in upstream: + // - GCC 10.3: 8dd1c1085587c9f8a21bb5e588dfe1e8cdbba79e + // - GCC 11.1: 1dfd95f0a0ca1d9e6cbc00e6cbfd1fa20a98f312 + // For more details see the commits mentioned above. + return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(), + MOVEFILE_REPLACE_EXISTING) != 0; +#else std::error_code error; fs::rename(src, dest, error); return !error; +#endif } /** -- cgit v1.2.3 From dc01cbc538765f64326bca30952c83e3862d0d54 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 13 Feb 2022 17:35:51 +0200 Subject: test: Add fs_tests/rename unit test Co-authored-by: Vasil Dimov --- src/test/fs_tests.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/fs_tests.cpp b/src/test/fs_tests.cpp index 1256395849..4fb2c23d98 100644 --- a/src/test/fs_tests.cpp +++ b/src/test/fs_tests.cpp @@ -118,4 +118,38 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream) } } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_CASE(rename) +{ + const fs::path tmpfolder{m_args.GetDataDirBase()}; + + const fs::path path1{GetUniquePath(tmpfolder)}; + const fs::path path2{GetUniquePath(tmpfolder)}; + + const std::string path1_contents{"1111"}; + const std::string path2_contents{"2222"}; + + { + std::ofstream file{path1}; + file << path1_contents; + } + + { + std::ofstream file{path2}; + file << path2_contents; + } + + // Rename path1 -> path2. + BOOST_CHECK(RenameOver(path1, path2)); + + BOOST_CHECK(!fs::exists(path1)); + + { + std::ifstream file{path2}; + std::string contents; + file >> contents; + BOOST_CHECK_EQUAL(contents, path1_contents); + } + fs::remove(path2); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3