Commit ca7e923c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Task: Fix crash when trying to restore a file that is not present anymore

parent 3c9dd117
......@@ -140,16 +140,41 @@ bool Task::restoreLinkedEntities( )
parentFolderFs = fsFactory->createDirectory( utils::file::directory( mrl ) );
if ( parentFolderFs == nullptr )
return false;
auto files = parentFolderFs->files();
auto it = std::find_if( begin( files ), end( files ), [this]( std::shared_ptr<fs::IFile> f ) {
return f->mrl() == mrl;
});
if ( it == end( files ) )
try
{
auto files = parentFolderFs->files();
auto it = std::find_if( begin( files ), end( files ), [this]( std::shared_ptr<fs::IFile> f ) {
return f->mrl() == mrl;
});
if ( it == end( files ) )
{
LOG_ERROR( "Failed to restore fs::IFile associated with ", mrl );
return false;
}
fileFs = *it;
}
catch ( const std::system_error& ex )
{
LOG_ERROR( "Failed to restore fs::IFile associated with ", mrl );
// If we never found the file yet, we can delete the task. It will be
// recreated upon next discovery
if ( file == nullptr )
{
LOG_WARN( "Failed to restore file system instances for mrl ", mrl, "."
" Removing the task until it gets detected again." );
destroy( m_ml, m_id );
}
else
{
// Otherwise we need to postpone it, although most likely we will
// detect that the file is now missing, and we won't try to restore
// this task until it comes back (since the task restoration request
// includes the file.is_present flag)
LOG_WARN( "Failed to restore file system instances for mrl ", mrl, "."
" Postponing the task." );
}
return false;
}
fileFs = *it;
if ( file != nullptr )
media = file->media();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment