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};
|
2023-01-08 17:37:28 +01:00
|
|
|
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);
|
|
|
|
}
|
2023-04-02 21:41:01 +02:00
|
|
|
catch(LooqsGeneralException &e)
|
|
|
|
{
|
|
|
|
Logger::error() << e.message << Qt::endl;
|
|
|
|
sfr = PROCESSFAIL;
|
|
|
|
}
|
|
|
|
|
2022-04-22 09:07:10 +02:00
|
|
|
catch(std::exception &e)
|
2022-04-14 14:58:07 +02:00
|
|
|
{
|
2023-04-02 21:41:01 +02:00
|
|
|
Logger::error() << e.what() << Qt::endl;
|
2022-04-14 14:58:07 +02:00
|
|
|
sfr = PROCESSFAIL; // well...
|
|
|
|
}
|
2023-04-02 21:41:01 +02:00
|
|
|
|
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();
|
|
|
|
}
|
2023-01-08 17:37:28 +01:00
|
|
|
|
|
|
|
void FileScanWorker::setFileSaverOptions(FileSaverOptions options)
|
|
|
|
{
|
|
|
|
this->fileSaverOptions = options;
|
|
|
|
}
|