mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-07-24 03:54:26 +08:00
refs #41, fs::rename now overwrites existing files on windows, extended tests
This commit is contained in:
parent
5a933d5c52
commit
c37d756a7f
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user