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

Abort parsing early in case a file/media gets deleted concurrently

This is a best effort approch, as locking would hurt the performances
dramatically (basically, no parsing while discovering)
parent 903e697e
......@@ -128,6 +128,9 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
return parser::Task::Status::Fatal;
}
if ( task.file->isDeleted() == true || task.media->isDeleted() == true )
return parser::Task::Status::Fatal;
task.file->markStepCompleted( File::ParserStep::MetadataAnalysis );
// Save ourselves from the useless processing of a thumbnail later if
// we're analyzing an audio file
......
......@@ -150,6 +150,9 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
return res;
LOG_INFO( "Done generating ", file->mrl(), " thumbnail" );
if ( task.file->isDeleted() == true || task.media->isDeleted() == true )
return parser::Task::Status::Fatal;
file->markStepCompleted( File::ParserStep::Thumbnailer );
m_notifier->notifyMediaModification( task.media );
......
......@@ -26,6 +26,7 @@
#include "ParserService.h"
#include "Parser.h"
#include "Media.h"
namespace medialibrary
{
......@@ -155,11 +156,16 @@ void ParserService::mainloop()
{
LOG_INFO( "Executing ", serviceName, " task on ", task->file->mrl() );
auto chrono = std::chrono::steady_clock::now();
task->file->startParserStep();
status = run( *task );
auto duration = std::chrono::steady_clock::now() - chrono;
LOG_INFO( "Done executing ", serviceName, " task on ", task->file->mrl(), " in ",
std::chrono::duration_cast<std::chrono::milliseconds>( duration ).count(), "ms" );
if ( task->file->isDeleted() || task->media->isDeleted() )
status = parser::Task::Status::Fatal;
else
{
task->file->startParserStep();
status = run( *task );
auto duration = std::chrono::steady_clock::now() - chrono;
LOG_INFO( "Done executing ", serviceName, " task on ", task->file->mrl(), " in ",
std::chrono::duration_cast<std::chrono::milliseconds>( duration ).count(), "ms" );
}
}
catch ( const std::exception& ex )
{
......
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