mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#24331: Revert back MoveFileExW
call for MinGW-w64
This commit is contained in:
parent
15e794bdd8
commit
6c7335e002
@ -118,6 +118,40 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
BOOST_AUTO_TEST_CASE(create_directories)
|
||||
{
|
||||
|
@ -1138,9 +1138,20 @@ std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string&
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user