From c37d756a7f7701f70e83fe7f5ddacefd68cd9a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Sch=C3=BCmann?= Date: Fri, 22 Nov 2019 18:48:10 +0100 Subject: [PATCH] refs #41, fs::rename now overwrites existing files on windows, extended tests --- include/ghc/filesystem.hpp | 2 +- test/filesystem_test.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index a5ae8a5..32c289a 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -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(from.u8string()).c_str(), detail::fromUtf8(to.u8string()).c_str())) { + if (!MoveFileExW(detail::fromUtf8(from.u8string()).c_str(), detail::fromUtf8(to.u8string()).c_str(), (DWORD)MOVEFILE_REPLACE_EXISTING)) { ec = detail::make_system_error(); } } diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 9b79584..7369fcd 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -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);