looqs/shared/filescanworker.cpp

50 lines
1.0 KiB
C++
Raw Normal View History

2022-04-14 14:58:07 +02:00
#include "filescanworker.h"
#include "logger.h"
2022-04-15 21:06:19 +02:00
FileScanWorker::FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &queue, int batchsize,
std::atomic<bool> &stopToken)
2022-04-14 14:58:07 +02:00
{
this->dbService = &db;
this->queue = &queue;
this->batchsize = batchsize;
2022-04-15 21:06:19 +02:00
this->stopToken = &stopToken;
2022-04-14 14:58:07 +02:00
}
void FileScanWorker::run()
{
FileSaver saver{*this->dbService};
saver.setFileSaverOptions(this->fileSaverOptions);
2022-04-14 14:58:07 +02:00
auto paths = queue->dequeue(batchsize);
for(QString &path : paths)
{
SaveFileResult sfr;
try
{
sfr = saver.addFile(path);
}
catch(LooqsGeneralException &e)
{
Logger::error() << e.message << Qt::endl;
sfr = PROCESSFAIL;
}
catch(std::exception &e)
2022-04-14 14:58:07 +02:00
{
Logger::error() << e.what() << Qt::endl;
2022-04-14 14:58:07 +02:00
sfr = PROCESSFAIL; // well...
}
2022-04-14 14:58:07 +02:00
emit result({path, sfr});
2022-04-15 21:06:19 +02:00
if(stopToken->load(std::memory_order_relaxed)) // TODO: relaxed should suffice here, but recheck
{
emit finished();
return;
}
2022-04-14 14:58:07 +02:00
}
emit finished();
}
void FileScanWorker::setFileSaverOptions(FileSaverOptions options)
{
this->fileSaverOptions = options;
}