Я использую boost :: filesystem для переименования файла следующим образом:
boost::filesystem::rename(tmpFileName, targetFile);
tmpFileName / targetFile имеют тип boost :: filsystem :: path.
При этом я перебираю каталог, используя этот код в другом потоке:
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;
}
}
}
Когда этот код выполняется, я получаю исключение при переименовании:
boost::filesystem::rename: The process cannot access the file because it is being used by another process
Возможно ли, что итерация и операция переименования конфликтуют, потому что они оба обращаются к inode каталога, или у меня есть другая проблема?