From 1dfd95f0a0ca1d9e6cbc00e6cbfd1fa20a98f312 Mon Sep 17 00:00:00 2001
From: Jonathan Wakely
Date: Fri, 12 Feb 2021 15:13:02 +0000
Subject: [PATCH] libstdc++: Fix filesystem::rename on Windows [PR 98985]
The _wrename function won't overwrite an existing file, so use
MoveFileEx instead. That allows renaming directories over files, which
POSIX doesn't allow, so check for that case explicitly and report an
error.
Also document the deviation from the expected behaviour, and add a test
for filesystem::rename which was previously missing.
The Filesystem TS experimental::filesystem::rename doesn't have that
extra code to handle directories correctly, so the relevant parts of the
new test are not run on Windows.
libstdc++-v3/ChangeLog:
* doc/xml/manual/status_cxx2014.xml: Document implementation
specific properties of std::experimental::filesystem::rename.
* doc/xml/manual/status_cxx2017.xml: Document implementation
specific properties of std::filesystem::rename.
* doc/html/*: Regenerate.
* src/c++17/fs_ops.cc (fs::rename): Implement correct behaviour
for directories on Windows.
* src/filesystem/ops-common.h (__gnu_posix::rename): Use
MoveFileExW on Windows.
* testsuite/27_io/filesystem/operations/rename.cc: New test.
* testsuite/experimental/filesystem/operations/rename.cc: New test.
---
libstdc++-v3/doc/html/index.html | 2 +-
libstdc++-v3/doc/html/manual/index.html | 2 +-
libstdc++-v3/doc/html/manual/intro.html | 2 +-
libstdc++-v3/doc/html/manual/status.html | 35 +++-
.../doc/xml/manual/status_cxx2014.xml | 26 ++-
.../doc/xml/manual/status_cxx2017.xml | 15 +-
libstdc++-v3/src/c++17/fs_ops.cc | 30 +++
libstdc++-v3/src/filesystem/ops-common.h | 11 +-
.../27_io/filesystem/operations/rename.cc | 181 ++++++++++++++++++
.../filesystem/operations/rename.cc | 180 +++++++++++++++++
10 files changed, 474 insertions(+), 10 deletions(-)
create mode 100644 libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
create mode 100644 libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
diff --git a/libstdc++-v3/doc/html/index.html b/libstdc++-v3/doc/html/index.html
index 587d4ee819a..772009a816b 100644
--- a/libstdc++-v3/doc/html/index.html
+++ b/libstdc++-v3/doc/html/index.html
@@ -23,7 +23,7 @@