Opened 8 months ago

Last modified 11 days 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:


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:

Attachments (0)

Change History (2)

comment:2 Changed 11 days ago by John Maddock

Component: Nonefilesystem
Owner: set to Beman Dawes

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain Beman Dawes.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.