Modify

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#1061 closed Bugs (fixed)

boost::filesystem::basic_recursive_directory_iterator fails on empty directories.

Reported by: jrowe@… Owned by: Beman Dawes
Milestone: Boost 1.35.0 Component: filesystem
Version: Boost 1.34.0 Severity: Problem
Keywords: recursive_directory_iterator empty directory Cc:

Description

See the following code (http://lists.boost.org/Archives/boost/2006/10/111230.php):

int main(int argc, char *argv[]) 
{ 
     fs::path p("c:\\empty_folder"); // a empty folder 
     fs::recursive_directory_iterator iter(p); 
     if (iter != fs::recursive_directory_iterator()) 
         iter->status(); // <== cause a assertion failure 
     return 0; 
} 

It might be able to be fixed by modifying convenience.hpp in the following way (only informally tested for an empty top-level directory):

    //  constructors
    template<class Path>
    basic_recursive_directory_iterator<Path>::
      basic_recursive_directory_iterator( const Path & dir_path )
      : m_imp( new detail::recur_dir_itr_imp<Path> )
    {
      m_imp->m_stack.push( basic_directory_iterator<Path>( dir_path ) );
      if (m_imp->m_stack.top () == basic_directory_iterator<Path> ())
      {
          m_imp.reset ();
      }
    }

    template<class Path>
    basic_recursive_directory_iterator<Path>::
      basic_recursive_directory_iterator( const Path & dir_path, system_error_type & ec )
      : m_imp( new detail::recur_dir_itr_imp<Path> )
    {
      m_imp->m_stack.push( basic_directory_iterator<Path>( dir_path, std::nothrow ) );
      if (m_imp->m_stack.top () == basic_directory_iterator<Path> ())
      {
          m_imp.reset ();
      }
      m_imp->m_no_throw = true;
    }

I haven't tested this fix with any significant rigor. I am just reporting the bug so it can be tracked, and suggesting the code where the problem is.

Attachments (0)

Change History (4)

comment:1 Changed 10 years ago by Eric Niebler

Owner: set to Beman Dawes

comment:2 Changed 10 years ago by Beman Dawes

Milestone: To Be DeterminedBoost 1.35.0
Status: newassigned

I've confirm that this is a bug, and added a test case to convenience_test.cpp that detects it.

The fix is scheduled for 1.35.0.

Thanks,

--Beman

comment:3 Changed 10 years ago by Beman Dawes

Resolution: fixed
Status: assignedclosed

Fixed. See revision 38978 on branches/filesystem.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Beman Dawes.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.