[Bug libstdc++/97654] New: std::filesystem::copy() can't overwrite existing symlink
devl@adrian-ebeling.de
gcc-bugzilla@gcc.gnu.org
Sat Oct 31 14:34:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97654
Bug ID: 97654
Summary: std::filesystem::copy() can't overwrite existing
symlink
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: devl@adrian-ebeling.de
Target Milestone: ---
Created attachment 49480
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49480&action=edit
Full output with -v
std::filesystem::copy() with copy_options = copy_symlinks | overwrite_existing
does not overwrite existing symlinks. Instead it produces the following error:
terminate called after throwing an instance of
'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot copy: Invalid argument [link] [link_copy]
Using gcc-9.3.0 on Ubuntu focal.
Here's a simple shell script that creates the source files and produces the
error:
#!/bin/bash
# Create a regular file and two links to it
touch dest
ln -sf dest link
ln -sf dest link_copy
# Create a cpp program that uses std::filesystem to copy "link" to "link_copy",
# overwriting the existing link_copy
cat <<EOF > copyLink.cpp
#include <filesystem>
int main() {
using namespace std::filesystem;
copy("link", "link_copy",
copy_options::copy_symlinks | copy_options::overwrite_existing);
}
EOF
#compile and run
g++ -v --save-temps -std=c++17 copyLink.cpp -o copyLink
./copyLink
More information about the Gcc-bugs
mailing list