Opened 5 years ago

Last modified 4 years ago

#13217 new Bugs

remove_all(const path& p, system::error_code& ec) is not supposed to throw filesystem_error, but still can

Reported by: Brad Spencer <bspencer@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

I will be submitting a github pull request in association with this ticket.

According to the documentation, uintmax_t remove_all(const path& p, system::error_code& ec) is not supposed to throw filesystem_error. However, when the directory_iterator used in the loop inside the implementation helper function remove_all_aux() is incremented, it's not done in a way that considers the ec argument. So, when incrementing the iterator fails, the operator++() on the directory_iterator throws, which leads to remove_all() incorrectly throwing.

To fix this, it seems that one can take the same approach as the recent changes for Fix #7307 (commit 4e4374336c640c2717f6a1b168406e11bdf7d6f1) and replace the ++itr call in the loop with an explicit call to either directory_iterator::increment(system::error_code& ec) whenever an ec argument is in effect. This should prevent remove_all() from throwing in such cases and thus allow it to conform to its interface specification.

BTW I also found these possibly related tickets in Trac:

Change History (2)

comment:2 by John Maddock, 4 years ago

Component: Nonefilesystem
Owner: set to Beman Dawes
Note: See TracTickets for help on using tickets.