[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-10-04 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

Jonathan Wakely  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #11 from Jonathan Wakely  ---
Fixed for 11.5, 12.4 and 13.2

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-10-04 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #10 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:d69407149194e2a7ee20537c76acb1976c8659be

commit r11-11048-gd69407149194e2a7ee20537c76acb1976c8659be
Author: Jonathan Wakely 
Date:   Tue Mar 21 12:29:08 2023 +

libstdc++: Make std::filesystem::copy_file work for procfs [PR108178]

The size reported by stat is always zero for some special files such as
those under /proc, which means the current copy_file implementation
thinks there is nothing to copy. Instead of trusting the stat value, try
to read a character from a streambuf and check for EOF.

For the backport, we also need to avoid trying to use sendfile when stat
reports a zero size, so that we use streambufs to copy the file.

libstdc++-v3/ChangeLog:

PR libstdc++/108178
* src/filesystem/ops-common.h (do_copy_file): Check for empty
files by trying to read a character.
* testsuite/27_io/filesystem/operations/copy_file_108178.cc:
New test.

(cherry picked from commit 07a0e108247f23fcb919c61595adae143f1ea02a)

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-10-03 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #9 from CVS Commits  ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:f85947338197b12b77aa5eb0eb2d1b4ea7dbdd54

commit r12-9908-gf85947338197b12b77aa5eb0eb2d1b4ea7dbdd54
Author: Jonathan Wakely 
Date:   Tue Mar 21 12:29:08 2023 +

libstdc++: Make std::filesystem::copy_file work for procfs [PR108178]

The size reported by stat is always zero for some special files such as
those under /proc, which means the current copy_file implementation
thinks there is nothing to copy. Instead of trusting the stat value, try
to read a character from a streambuf and check for EOF.

For the backport, we also need to avoid trying to use sendfile when stat
reports a zero size, so that we use streambufs to copy the file.

libstdc++-v3/ChangeLog:

PR libstdc++/108178
* src/filesystem/ops-common.h (do_copy_file): Check for empty
files by trying to read a character.
* testsuite/27_io/filesystem/operations/copy_file_108178.cc:
New test.

(cherry picked from commit 07a0e108247f23fcb919c61595adae143f1ea02a)

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-06-06 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

Jonathan Wakely  changed:

   What|Removed |Added

   Target Milestone|--- |11.5

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-06-06 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #8 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:c0a57904308ad0f10833f38cb207c750e5658b6b

commit r13-7420-gc0a57904308ad0f10833f38cb207c750e5658b6b
Author: Jonathan Wakely 
Date:   Tue Mar 21 12:29:08 2023 +

libstdc++: Make std::filesystem::copy_file work for procfs [PR108178]

The size reported by stat is always zero for some special files such as
those under /proc, which means the current copy_file implementation
thinks there is nothing to copy. Instead of trusting the stat value, try
to read a character from a streambuf and check for EOF.

For the backport, we also need to avoid trying to use sendfile when stat
reports a zero size, so that we use streambufs to copy the file.

libstdc++-v3/ChangeLog:

PR libstdc++/108178
* src/filesystem/ops-common.h (do_copy_file): Check for empty
files by trying to read a character.
* testsuite/27_io/filesystem/operations/copy_file_108178.cc:
New test.

(cherry picked from commit 07a0e108247f23fcb919c61595adae143f1ea02a)

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-06-06 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #7 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:07a0e108247f23fcb919c61595adae143f1ea02a

commit r14-1570-g07a0e108247f23fcb919c61595adae143f1ea02a
Author: Jonathan Wakely 
Date:   Tue Mar 21 12:29:08 2023 +

libstdc++: Make std::filesystem::copy_file work for procfs [PR108178]

The size reported by stat is always zero for some special files such as
those under /proc, which means the current copy_file implementation
thinks there is nothing to copy. Instead of trusting the stat value, try
to read a character from a streambuf and check for EOF.

libstdc++-v3/ChangeLog:

PR libstdc++/108178
* src/filesystem/ops-common.h (do_copy_file): Check for empty
files by trying to read a character.
* testsuite/27_io/filesystem/operations/copy_file_108178.cc:
New test.

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-03-22 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #6 from Jonathan Wakely  ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614415.html

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2023-03-21 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

Jonathan Wakely  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |redi at gcc dot gnu.org

--- Comment #5 from Jonathan Wakely  ---
I have a patch for GCC 14 stage 1.

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2022-12-20 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #4 from Richard Biener  ---
In hindsight the files in /proc should probably have been named pipes, not
regular files.

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2022-12-19 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #3 from Jonathan Wakely  ---
On the other hand, it's not a bug in /proc, because the size of some of those
files might vary dynamically, and the size isn't known until you try to read
it. So even if we got a size from stat, we might read a different number of
bytes once we open it, and so sendfile wouldn't copy the whole thing anyway.
And on the gripping hand, reading from /proc could be considered undefined
behaviour because files that are changing while performing std::filesystem
operations cause races and so the behaviour is not defined by the standard.

But we can make it work in practice.

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2022-12-19 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2022-12-19
 Ever confirmed|0   |1

--- Comment #2 from Jonathan Wakely  ---
Yes, but we should probably add a workaround anyway.

Maybe we should not use sendfile for zero-sized files, and use fstream instead.
That will copy until EOF, without caring about the file size obtained from
stat(2). For real files that actually do have zero size that might be slightly
slower than attempting to use sendfile, but hopefully not too bad. I'll try to
benchmark it.

[Bug libstdc++/108178] Filesystem::copy_file can't copy from /proc on Linux machines

2022-12-19 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108178

--- Comment #1 from Richard Biener  ---
But that's a bug of the procfs filesystem, not of the standard library.