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

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