Skip to content

Iteration through directory fails on Linux, if file is removed during iteration #314

@martin5233

Description

@martin5233

The following small test program fails on Linux with Boost 1.85, but not with 1.81:

bfs::ofstream out("/tmp/mytest");
out.close();

bfs::directory_iterator it("/tmp");
bfs::remove("/tmp/mytest");

while(it != bfs::directory_iterator())
 {
     if (bfs::is_regular_file(it->status()))
     {
     }
   ++it;
}

While the code above does not make much sense, it also occurs, if a file is removed by a separate process, while a directory iteration is ongoing. The generated exception is the following:

terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
  what():  boost::filesystem::directory_entry::refresh: No such file or directory [system:2]: "/tmp/mytest"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions