]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix overwriting files with fs::copy_file on Windows
authorJonathan Wakely <jwakely@redhat.com>
Tue, 30 Jul 2024 09:55:55 +0000 (10:55 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 30 Jul 2024 13:36:06 +0000 (14:36 +0100)
commit017e3f89b081e4828a588a3bd27b5feacea042b7
treea3f746103cc1b4b1e428649c6136c77f4a855841
parent658193658f05e9a8ebf0bce8bab15555f43bfee1
libstdc++: Fix overwriting files with fs::copy_file on Windows

There are no inode numbers on Windows filesystems, so stat_type::st_ino
is always zero and the check for equivalent files in do_copy_file was
incorrectly identifying distinct files as equivalent. This caused
copy_file to incorrectly report errors when trying to overwrite existing
files.

The fs::equivalent function already does the right thing on Windows, so
factor that logic out into a new function that can be reused by
fs::copy_file.

The tests for fs::copy_file were quite inadequate, so this also adds
checks for that function's error conditions.

libstdc++-v3/ChangeLog:

* src/c++17/fs_ops.cc (auto_win_file_handle): Change constructor
parameter from const path& to const wchar_t*.
(fs::equiv_files): New function.
(fs::equivalent): Use equiv_files.
* src/filesystem/ops-common.h (fs::equiv_files): Declare.
(do_copy_file): Use equiv_files.
* src/filesystem/ops.cc (fs::equiv_files): Define.
(fs::copy, fs::equivalent): Use equiv_files.
* testsuite/27_io/filesystem/operations/copy.cc: Test
overwriting directory contents recursively.
* testsuite/27_io/filesystem/operations/copy_file.cc: Test
overwriting existing files.
libstdc++-v3/src/c++17/fs_ops.cc
libstdc++-v3/src/filesystem/ops-common.h
libstdc++-v3/src/filesystem/ops.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/copy_file.cc