2019-04-06 17:16:42 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QException>
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QtConcurrent/QtConcurrentMap>
|
|
|
|
#include "commandadd.h"
|
2019-04-16 08:52:43 +02:00
|
|
|
#include "logger.h"
|
2019-04-06 17:16:42 +02:00
|
|
|
|
2022-04-14 15:03:19 +02:00
|
|
|
void CommandAdd::indexerFinished()
|
|
|
|
{
|
|
|
|
IndexResult result = indexer->getResult();
|
|
|
|
|
|
|
|
Logger::info() << "Total: " << result.total() << Qt::endl;
|
|
|
|
Logger::info() << "Added: " << result.addedPaths << Qt::endl;
|
|
|
|
Logger::info() << "Skipped: " << result.skippedPaths << Qt::endl;
|
|
|
|
auto failedPathsCount = result.erroredPaths;
|
|
|
|
Logger::info() << "Failed: " << failedPathsCount << Qt::endl;
|
|
|
|
if(failedPathsCount > 0)
|
|
|
|
{
|
|
|
|
Logger::info() << "Failed paths: " << Qt::endl;
|
2023-03-12 16:41:31 +01:00
|
|
|
for(const QString &paths : result.failedPaths())
|
2022-04-14 15:03:19 +02:00
|
|
|
{
|
|
|
|
Logger::info() << paths << Qt::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 09:33:56 +02:00
|
|
|
int ret = 0;
|
|
|
|
if(!keepGoing && failedPathsCount > 0)
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
emit finishedCmd(ret);
|
2022-04-14 15:03:19 +02:00
|
|
|
}
|
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
int CommandAdd::handle(QStringList arguments)
|
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
2019-04-30 23:43:31 +02:00
|
|
|
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. "
|
2019-04-30 23:43:31 +02:00
|
|
|
"Set -t 1 to avoid this behavior, but processing will be slower. "},
|
2023-01-08 17:37:28 +01:00
|
|
|
{{"n", "no-content"}, "Only add paths to database. Do not index content"},
|
|
|
|
{{"f", "fill-content"}, "Index content for files previously indexed with -n"},
|
|
|
|
{"tags", "Comma-separated list of tags to assign"},
|
2019-04-16 08:52:43 +02:00
|
|
|
{{"t", "threads"}, "Number of threads to use.", "threads"}});
|
2019-04-06 17:16:42 +02:00
|
|
|
parser.addHelpOption();
|
2022-06-23 11:09:55 +02:00
|
|
|
parser.addPositionalArgument("add", "Add paths to the index",
|
|
|
|
"add [paths...]. If no path is given, read from stdin, one path per line.");
|
2019-04-06 17:16:42 +02:00
|
|
|
|
|
|
|
parser.process(arguments);
|
2022-06-06 09:33:56 +02:00
|
|
|
this->keepGoing = parser.isSet("continue");
|
2023-01-08 17:37:28 +01:00
|
|
|
bool pathsOnly = parser.isSet("no-content");
|
|
|
|
bool fillContent = parser.isSet("fill-content");
|
2019-04-06 17:16:42 +02:00
|
|
|
if(parser.isSet("threads"))
|
|
|
|
{
|
|
|
|
QString threadsCount = parser.value("threads");
|
|
|
|
QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt());
|
|
|
|
}
|
|
|
|
|
2023-01-08 17:37:28 +01:00
|
|
|
if(pathsOnly && fillContent)
|
|
|
|
{
|
|
|
|
Logger::error() << "Invalid options: -n and -f cannot both be set";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
QStringList files = parser.positionalArguments();
|
|
|
|
|
|
|
|
if(files.length() == 0)
|
|
|
|
{
|
|
|
|
QTextStream stream(stdin);
|
|
|
|
|
|
|
|
while(!stream.atEnd())
|
|
|
|
{
|
|
|
|
QString path = stream.readLine();
|
|
|
|
files.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 17:37:28 +01:00
|
|
|
FileSaverOptions fileSaverOptions;
|
|
|
|
fileSaverOptions.keepGoing = keepGoing;
|
2023-01-08 17:37:28 +01:00
|
|
|
fileSaverOptions.fillExistingContentless = fillContent;
|
|
|
|
fileSaverOptions.metadataOnly = pathsOnly;
|
2023-01-08 17:37:28 +01:00
|
|
|
fileSaverOptions.verbose = false;
|
|
|
|
|
2022-04-14 15:03:19 +02:00
|
|
|
indexer = new Indexer(*this->dbService);
|
2023-01-08 17:37:28 +01:00
|
|
|
indexer->setFileSaverOptions(fileSaverOptions);
|
|
|
|
|
2022-04-14 15:03:19 +02:00
|
|
|
indexer->setTargetPaths(files.toVector());
|
|
|
|
|
|
|
|
connect(indexer, &Indexer::pathsCountChanged, this,
|
|
|
|
[](int pathsCount) { Logger::info() << "Found paths: " << pathsCount << Qt::endl; });
|
|
|
|
connect(indexer, &Indexer::indexProgress, this,
|
2023-03-12 16:41:31 +01:00
|
|
|
[](int pathsCount, unsigned int /*added*/, unsigned int /*skipped*/, unsigned int /*failed*/,
|
|
|
|
unsigned int /*totalCount*/) { Logger::info() << "Processed files: " << pathsCount << Qt::endl; });
|
2022-04-14 15:03:19 +02:00
|
|
|
connect(indexer, &Indexer::finished, this, &CommandAdd::indexerFinished);
|
|
|
|
|
|
|
|
this->autoFinish = false;
|
|
|
|
indexer->beginIndexing();
|
2019-04-06 17:16:42 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|