On win32 fs::rename should overwrite file if exists
thefallentree opened this issue · 2 comments
thefallentree commented
Currently , fs::rename() will return with error 183, if destination file already exists. The standard indicate that it must overwrite file , here is the patch to use MoveFileExW instead.
GHC_INLINE void rename(const path& from, const path& to, std::error_code& ec) noexcept
{
ec.clear();
#ifdef GHC_OS_WINDOWS
if (from != to) {
if (!MoveFileExW(detail::fromUtf8<std::wstring>(from.u8string()).c_str(), detail::fromUtf8<std::wstring>(to.u8string()).c_str(), (DWORD) MOVEFILE_REPLACE_EXISTING)) {
ec = detail::make_system_error();
}
}
#else
if (from != to) {
if (::rename(from.c_str(), to.c_str()) != 0) {
ec = detail::make_system_error();
}
}
#endif
}
gulrak commented
Indeed, thanks! Will push a fix with additional tests on master after my working hours.
gulrak commented
Fix released with v1.2.10