filesystem::recursive_directory_iterator quits on unreadable directory
Version: boost 1.36
Library: filesystem
Platform: Linux
Compiler: g++ 4.3.0
The increment operator in filesystem::recursive_directory_iterator
throws an exception when trying to enter an unreadable directory
(permissions, no-such-device, etc.). Often (usually?), a user wants to
be able to skip the unreadable directory and continue the iteration over
the rest of the directory tree.
Catching this exception doesn't help because the iterator hasn't been
incremented and I couldn't figure a way to skip over the unreadble
directory.
The following modification of filesystem/convenience.hpp catches the
exception at a low enough level to allow the directory to be skipped
over.
Is there a better way of handling this? Thanks.
--- /usr/local/include/boost-1_36/boost/filesystem/convenience.hpp 2008-09-30 17:34:10.000000000 -0400
+++ boost/filesystem/convenience.hpp 2008-10-02 16:40:43.000000000 -0400
@@ -239,10 +239,15 @@
else if ( is_directory( m_imp->m_stack.top()->status() ) )
{
system::error_code ec;
- m_imp->m_stack.push(
- m_imp->m_no_throw
- ? basic_directory_iterator<Path>( *m_imp->m_stack.top(), ec )
- : basic_directory_iterator<Path>( *m_imp->m_stack.top() ) );
+ const Path& top = *m_imp->m_stack.top();
+ m_imp->m_stack.push(end_itr);
+ try {
+ m_imp->m_stack.top() =
+ m_imp->m_no_throw
+ ? basic_directory_iterator<Path>( top, ec )
+ : basic_directory_iterator<Path>( top );
+ }
+ catch ( ... ) { }
if ( m_imp->m_stack.top() != end_itr )
{
++m_imp->m_level;
--
Charles Karney
On Thursday 02 October 2008 16:42:24 Charles Karney wrote:
The increment operator in filesystem::recursive_directory_iterator throws an exception when trying to enter an unreadable directory (permissions, no-such-device, etc.). Often (usually?), a user wants to be able to skip the unreadable directory and continue the iteration over the rest of the directory tree.
Catching this exception doesn't help because the iterator hasn't been incremented and I couldn't figure a way to skip over the unreadble directory.
Could you please file a trac item for this? The patch that you have proposed does not seem right; the user might wish to be informed. Perhaps the right approach is to throw the exception but ensure that the user can still skip over the unreadable directory after catching the exception. Regards, Ravi
Ravi wrote:
On Thursday 02 October 2008 16:42:24 Charles Karney wrote:
The increment operator in filesystem::recursive_directory_iterator throws an exception when trying to enter an unreadable directory (permissions, no-such-device, etc.). Often (usually?), a user wants to be able to skip the unreadable directory and continue the iteration over the rest of the directory tree.
Catching this exception doesn't help because the iterator hasn't been incremented and I couldn't figure a way to skip over the unreadble directory.
Could you please file a trac item for this? The patch that you have proposed does not seem right; the user might wish to be informed. Perhaps the right approach is to throw the exception but ensure that the user can still skip over the unreadable directory after catching the exception.
Regards, Ravi
It's not obvious where I file a trac item... Please tell me where or else
feel free to file on my behalf. (I'm not a registered boost developer.)
I agree that it's not obvious how this error should be handled. Letting
the user trap the error and then skip the unreadable directory is a
possibility. However, wrapping a try/catch around the increment clause
of a for loop seems to be awkward. My patch effectively treats unreadable
directories as empty which would seem to be plausible default (and such
behavior should be documented of course).
--
Charles Karney
AMDG Charles Karney wrote:
It's not obvious where I file a trac item... Please tell me where or else feel free to file on my behalf. (I'm not a registered boost developer.)
svn.boost.org In Christ, Steven Watanabe
participants (3)
-
Charles Karney
-
Ravi
-
Steven Watanabe