views:

38

answers:

0

I'm using boost::filesystem to rename a file like this:

boost::filesystem::rename(tmpFileName, targetFile);

tmpFileName / targetFile are of type boost::filsystem::path.

While doing this, I iterate over the directory using this code in another thread:

directory_iterator end_itr;
for (directory_iterator itr(dirInfoPath); itr != end_itr; ++itr)
{
    path currentPath = itr->path();
    if (is_directory(itr->status()))
    {
        // skip directories
    }
    else 
    {
        std::string file_name = currentPath.leaf();
        if (!boost::algorithm::starts_with(file_name, "new") 
            && !boost::algorithm::starts_with(file_name, "finished")
            && boost::algorithm::ends_with(file_name, ".info"))
            {
                // save found filename in some variable
                return true;
            }
        }
    }

When this code is executed, I get an exception while renaming:

boost::filesystem::rename: The process cannot access the file because it is being used by another process

Is it possible that the iteration and the rename operation clash, because they both access the directory inode, or do I have some other problem?