looqs/cli/commandadd.cpp

68 řádky
1.9 KiB
C++
Surový Normální zobrazení Historie

#include <QFileInfo>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include <QDateTime>
#include <QMap>
#include <QTextStream>
#include <QException>
#include <QCommandLineParser>
#include <QMutex>
#include <QMutexLocker>
#include <QtConcurrent/QtConcurrentMap>
#include "commandadd.h"
#include "logger.h"
int CommandAdd::handle(QStringList arguments)
{
QCommandLineParser parser;
parser.addOptions({{{"c", "continue"},
2021-06-12 14:59:58 +02:00
"Continue adding files, don't exit on first error. If this option is not given, looqs will "
"exit asap, but it's possible that a few files will still be processed. "
"Set -t 1 to avoid this behavior, but processing will be slower. "},
{{"a", "all"}, "On error, no files should be added, even already processed ones"},
{{"v", "verbose"}, "Print skipped and added files"},
{{"t", "threads"}, "Number of threads to use.", "threads"}});
parser.addHelpOption();
2019-04-06 23:27:56 +02:00
parser.addPositionalArgument("add", "Add paths to the index", "add [paths...]");
parser.process(arguments);
bool keepGoing = parser.isSet("continue");
bool verbose = parser.isSet("verbose");
if(parser.isSet("all"))
{
2021-06-12 14:59:58 +02:00
throw LooqsGeneralException("To be implemented");
}
if(parser.isSet("threads"))
{
QString threadsCount = parser.value("threads");
QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt());
}
QStringList files = parser.positionalArguments();
if(files.length() == 0)
{
QTextStream stream(stdin);
while(!stream.atEnd())
{
QString path = stream.readLine();
files.append(path);
}
}
FileSaver saver(*this->dbService);
int numFilesCount = files.size();
int processedFilesCount = saver.addFiles(files.toVector(), keepGoing, verbose);
if(processedFilesCount != numFilesCount)
{
Logger::error() << "Errors occured while trying to add files to the database. Processed " << processedFilesCount
<< "out of" << numFilesCount << "files" << Qt::endl;
return 1;
}
return 0;
}