Modify

Ticket #1061 (closed Bugs: fixed)

Opened 7 years ago

Last modified 6 years ago

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

Reported by: jrowe@… Owned by: bemandawes
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

Change History

comment:1 Changed 7 years ago by eric_niebler

  • Owner set to bemandawes

comment:2 Changed 7 years ago by bemandawes

  • Status changed from new to assigned
  • Milestone changed from To Be Determined to Boost 1.35.0

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 7 years ago by bemandawes

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed. See revision 38978 on branches/filesystem.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.