Skip to content

Commit

Permalink
refs #41, fs::rename now overwrites existing files on windows, extend…
Browse files Browse the repository at this point in the history
…ed tests
  • Loading branch information
gulrak committed Nov 22, 2019
1 parent 5a933d5 commit c37d756
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4176,7 +4176,7 @@ GHC_INLINE void rename(const path& from, const path& to, std::error_code& ec) no
ec.clear();
#ifdef GHC_OS_WINDOWS
if (from != to) {
if (!MoveFileW(detail::fromUtf8<std::wstring>(from.u8string()).c_str(), detail::fromUtf8<std::wstring>(to.u8string()).c_str())) {
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();
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2444,12 +2444,20 @@ TEST_CASE("30.10.15.32 rename", "[filesystem][operations][fs.op.rename]")
{
TemporaryDirectory t(TempOpt::change_path);
std::error_code ec;
generateFile("foo");
generateFile("foo", 123);
fs::create_directory("dir1");
CHECK_NOTHROW(fs::rename("foo", "bar"));
CHECK(!fs::exists("foo"));
CHECK(fs::exists("bar"));
CHECK_NOTHROW(fs::rename("dir1", "dir2"));
CHECK(fs::exists("dir2"));
generateFile("foo2", 42);
CHECK_NOTHROW(fs::rename("bar", "foo2"));
CHECK(fs::exists("foo2"));
CHECK(fs::file_size("foo2") == 123u);
CHECK(!fs::exists("bar"));
CHECK_NOTHROW(fs::rename("foo2", "foo", ec));
CHECK(!ec);
CHECK_THROWS_AS(fs::rename("foobar", "barfoo"), fs::filesystem_error);
CHECK_NOTHROW(fs::rename("foobar", "barfoo", ec));
CHECK(ec);
Expand Down

0 comments on commit c37d756

Please sign in to comment.