public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion
@ 2021-02-26 15:42 fabian@ritter-vogt.de
  2021-02-26 15:49 ` [Bug libstdc++/99290] " marxin at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: fabian@ritter-vogt.de @ 2021-02-26 15:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

            Bug ID: 99290
           Summary: std::filesystem::copy does not always report errors
                    for recursion
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fabian@ritter-vogt.de
  Target Milestone: ---

For the case where a directory is copied to another directory with either
copy_options::recursive or copy_options::none, fs_copy.cc has this in
std::filesystem::copy:

      for (const directory_entry& x : directory_iterator(from))
        copy(x.path(), to/x.path().filename(), options, ec);

This does not check the value of "ec" after each call to copy. As successful
invocations of copy clear the error, only the last call to copy influences the
error code. As the order of entries returned by directory_iterator is
unspecified, it's also unspecified whether an error is reported if recursive
copying fails.

Test program:

#include <filesystem>

int main(int argc, char *argv[])
{
        std::filesystem::copy(std::filesystem::path{argv[1]},
                              std::filesystem::path{argv[2]},
                              std::filesystem::copy_options::none);
}

Compile and run like this:

> g++ fstest.cpp -std=c++17 -o fstest # Compile
> mkdir source dest
> mkdir source/emptydir dest/emptydir # Empty directories, noop for fs::copy
> touch source/file; echo "dst" > dest/file # Conflicting files to make fs::copy fail
> ./fstest source dest # Doesn't fail, because the empty directories overwrote the error code
> rmdir source/emptydir dest/emptydir # Drop the empty directories
> ./fstest source dest # Now it fails
terminate called after throwing an instance of
'std::filesystem::__cxx11::filesystem_error'
  what():  filesystem error: cannot copy: File exists [source] [dest]

Whether you see the same effect is highly dependent on your (file) system.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
@ 2021-02-26 15:49 ` marxin at gcc dot gnu.org
  2022-04-28 12:33 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-26 15:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-02-26
     Ever confirmed|0                           |1
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |redi at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
  2021-02-26 15:49 ` [Bug libstdc++/99290] " marxin at gcc dot gnu.org
@ 2022-04-28 12:33 ` cvs-commit at gcc dot gnu.org
  2022-04-28 13:31 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-28 12:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:4e117418fb71f508c479e0144500f4da9cc92520

commit r12-8303-g4e117418fb71f508c479e0144500f4da9cc92520
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Apr 28 13:06:31 2022 +0100

    libstdc++: Fix error reporting in filesystem::copy [PR99290]

    The recursive calls to filesystem::copy should stop if any of them
    reports an error.

    libstdc++-v3/ChangeLog:

            PR libstdc++/99290
            * src/c++17/fs_ops.cc (fs::copy): Pass error_code to
            directory_iterator constructor, and check on each iteration.
            * src/filesystem/ops.cc (fs::copy): Likewise.
            * testsuite/27_io/filesystem/operations/copy.cc: Check for
            errors during recursion.
            * testsuite/experimental/filesystem/operations/copy.cc:
            Likewise.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
  2021-02-26 15:49 ` [Bug libstdc++/99290] " marxin at gcc dot gnu.org
  2022-04-28 12:33 ` cvs-commit at gcc dot gnu.org
@ 2022-04-28 13:31 ` redi at gcc dot gnu.org
  2022-04-28 17:04 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-28 13:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpie@msc-ge.com

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 105422 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
                   ` (2 preceding siblings ...)
  2022-04-28 13:31 ` redi at gcc dot gnu.org
@ 2022-04-28 17:04 ` cvs-commit at gcc dot gnu.org
  2022-04-28 17:05 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-28 17:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:9821d286bce3edf1d36168f129bfc7fe99c15fc3

commit r11-9948-g9821d286bce3edf1d36168f129bfc7fe99c15fc3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Apr 28 13:06:31 2022 +0100

    libstdc++: Fix error reporting in filesystem::copy [PR99290]

    The recursive calls to filesystem::copy should stop if any of them
    reports an error.

    libstdc++-v3/ChangeLog:

            PR libstdc++/99290
            * src/c++17/fs_ops.cc (fs::copy): Pass error_code to
            directory_iterator constructor, and check on each iteration.
            * src/filesystem/ops.cc (fs::copy): Likewise.
            * testsuite/27_io/filesystem/operations/copy.cc: Check for
            errors during recursion.
            * testsuite/experimental/filesystem/operations/copy.cc:
            Likewise.

    (cherry picked from commit 4e117418fb71f508c479e0144500f4da9cc92520)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
                   ` (3 preceding siblings ...)
  2022-04-28 17:04 ` cvs-commit at gcc dot gnu.org
@ 2022-04-28 17:05 ` redi at gcc dot gnu.org
  2022-06-14 19:20 ` cvs-commit at gcc dot gnu.org
  2022-06-14 19:21 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-28 17:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.4

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 11.4 and 21.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
                   ` (4 preceding siblings ...)
  2022-04-28 17:05 ` redi at gcc dot gnu.org
@ 2022-06-14 19:20 ` cvs-commit at gcc dot gnu.org
  2022-06-14 19:21 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-14 19:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:43cbff3da5a856d1b18a9ad33b337ab829af73ed

commit r10-10833-g43cbff3da5a856d1b18a9ad33b337ab829af73ed
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Apr 28 13:06:31 2022 +0100

    libstdc++: Fix error reporting in filesystem::copy [PR99290]

    The recursive calls to filesystem::copy should stop if any of them
    reports an error.

    libstdc++-v3/ChangeLog:

            PR libstdc++/99290
            * src/c++17/fs_ops.cc (fs::copy): Pass error_code to
            directory_iterator constructor, and check on each iteration.
            * src/filesystem/ops.cc (fs::copy): Likewise.
            * testsuite/27_io/filesystem/operations/copy.cc: Check for
            errors during recursion.
            * testsuite/experimental/filesystem/operations/copy.cc:
            Likewise.

    (cherry picked from commit 4e117418fb71f508c479e0144500f4da9cc92520)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/99290] std::filesystem::copy does not always report errors for recursion
  2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
                   ` (5 preceding siblings ...)
  2022-06-14 19:20 ` cvs-commit at gcc dot gnu.org
@ 2022-06-14 19:21 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-14 19:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99290

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.4                        |10.4

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also fixed for 10.4 now.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-14 19:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26 15:42 [Bug libstdc++/99290] New: std::filesystem::copy does not always report errors for recursion fabian@ritter-vogt.de
2021-02-26 15:49 ` [Bug libstdc++/99290] " marxin at gcc dot gnu.org
2022-04-28 12:33 ` cvs-commit at gcc dot gnu.org
2022-04-28 13:31 ` redi at gcc dot gnu.org
2022-04-28 17:04 ` cvs-commit at gcc dot gnu.org
2022-04-28 17:05 ` redi at gcc dot gnu.org
2022-06-14 19:20 ` cvs-commit at gcc dot gnu.org
2022-06-14 19:21 ` redi at gcc dot gnu.org

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).