Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On win32 fs::rename should overwrite file if exists #41

Closed
thefallentree opened this issue Nov 22, 2019 · 2 comments
Closed

On win32 fs::rename should overwrite file if exists #41

thefallentree opened this issue Nov 22, 2019 · 2 comments
Assignees
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working
Milestone

Comments

@thefallentree
Copy link

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 gulrak self-assigned this Nov 22, 2019
@gulrak gulrak added the bug Something isn't working label Nov 22, 2019
@gulrak
Copy link
Owner

gulrak commented Nov 22, 2019

Indeed, thanks! Will push a fix with additional tests on master after my working hours.

@gulrak gulrak added this to the v1.2.10 milestone Nov 22, 2019
@gulrak gulrak added the available on master Fix is done on master branch, issue closed on next release label Nov 22, 2019
@gulrak
Copy link
Owner

gulrak commented Nov 24, 2019

Fix released with v1.2.10

@gulrak gulrak closed this as completed Nov 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants