public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/97654] New: std::filesystem::copy() can't overwrite existing symlink
@ 2020-10-31 14:34 devl@adrian-ebeling.de
2020-10-31 14:37 ` [Bug libstdc++/97654] " devl@adrian-ebeling.de
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: devl@adrian-ebeling.de @ 2020-10-31 14:34 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/97654] std::filesystem::copy() can't overwrite existing symlink
2020-10-31 14:34 [Bug libstdc++/97654] New: std::filesystem::copy() can't overwrite existing symlink devl@adrian-ebeling.de
@ 2020-10-31 14:37 ` devl@adrian-ebeling.de
2020-10-31 16:02 ` redi at gcc dot gnu.org
2020-10-31 17:47 ` devl@adrian-ebeling.de
2 siblings, 0 replies; 4+ messages in thread
From: devl@adrian-ebeling.de @ 2020-10-31 14:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97654
--- Comment #1 from devl@adrian-ebeling.de ---
Created attachment 49481
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49481&action=edit
intermediate files
.ii and .s files
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/97654] std::filesystem::copy() can't overwrite existing symlink
2020-10-31 14:34 [Bug libstdc++/97654] New: std::filesystem::copy() can't overwrite existing symlink devl@adrian-ebeling.de
2020-10-31 14:37 ` [Bug libstdc++/97654] " devl@adrian-ebeling.de
@ 2020-10-31 16:02 ` redi at gcc dot gnu.org
2020-10-31 17:47 ` devl@adrian-ebeling.de
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-31 16:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97654
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to devl from comment #0)
> Created attachment 49480 [details]
> 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]
I think that's the behaviour specified by the standard, see [fs.op.copy] p4
bullet (4.6).
Or the equivalent description at
https://en.cppreference.com/w/cpp/filesystem/copy
If from is a symbolic link, then
- If copy_options::skip_symlink is present in options, does nothing.
- Otherwise, if to does not exist and copy_options::copy_symlinks is present
in options, then behaves as if copy_symlink(from, to)
- Otherwise, reports an error
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/97654] std::filesystem::copy() can't overwrite existing symlink
2020-10-31 14:34 [Bug libstdc++/97654] New: std::filesystem::copy() can't overwrite existing symlink devl@adrian-ebeling.de
2020-10-31 14:37 ` [Bug libstdc++/97654] " devl@adrian-ebeling.de
2020-10-31 16:02 ` redi at gcc dot gnu.org
@ 2020-10-31 17:47 ` devl@adrian-ebeling.de
2 siblings, 0 replies; 4+ messages in thread
From: devl@adrian-ebeling.de @ 2020-10-31 17:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97654
devl@adrian-ebeling.de changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #3 from devl@adrian-ebeling.de ---
I suppose you're right.
If is_symlink(f), the overwrite_existing flag is not taken into account,
according to the standard.
Sounds like a standard oversight to me, though.
Sigh, I guess I just have to manually delete the destination beforehand if it's
a symlink. The thing is I have to copy a whole bunch of files and only some of
them are symlinks.
Thanks for your help.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-31 17:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-31 14:34 [Bug libstdc++/97654] New: std::filesystem::copy() can't overwrite existing symlink devl@adrian-ebeling.de
2020-10-31 14:37 ` [Bug libstdc++/97654] " devl@adrian-ebeling.de
2020-10-31 16:02 ` redi at gcc dot gnu.org
2020-10-31 17:47 ` devl@adrian-ebeling.de
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).