cli: CommandAdd: Implement --no-content and --fill-content
Dieser Commit ist enthalten in:
Ursprung
71789b5b56
Commit
8298b675aa
@ -44,20 +44,30 @@ int CommandAdd::handle(QStringList arguments)
|
|||||||
"Continue adding files, don't exit on first error. If this option is not given, looqs will "
|
"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. "
|
"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. "},
|
"Set -t 1 to avoid this behavior, but processing will be slower. "},
|
||||||
|
{{"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"},
|
||||||
{{"t", "threads"}, "Number of threads to use.", "threads"}});
|
{{"t", "threads"}, "Number of threads to use.", "threads"}});
|
||||||
|
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addPositionalArgument("add", "Add paths to the index",
|
parser.addPositionalArgument("add", "Add paths to the index",
|
||||||
"add [paths...]. If no path is given, read from stdin, one path per line.");
|
"add [paths...]. If no path is given, read from stdin, one path per line.");
|
||||||
|
|
||||||
parser.process(arguments);
|
parser.process(arguments);
|
||||||
this->keepGoing = parser.isSet("continue");
|
this->keepGoing = parser.isSet("continue");
|
||||||
|
bool pathsOnly = parser.isSet("no-content");
|
||||||
|
bool fillContent = parser.isSet("fill-content");
|
||||||
if(parser.isSet("threads"))
|
if(parser.isSet("threads"))
|
||||||
{
|
{
|
||||||
QString threadsCount = parser.value("threads");
|
QString threadsCount = parser.value("threads");
|
||||||
QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt());
|
QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pathsOnly && fillContent)
|
||||||
|
{
|
||||||
|
Logger::error() << "Invalid options: -n and -f cannot both be set";
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList files = parser.positionalArguments();
|
QStringList files = parser.positionalArguments();
|
||||||
|
|
||||||
if(files.length() == 0)
|
if(files.length() == 0)
|
||||||
|
@ -119,11 +119,29 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
|||||||
{
|
{
|
||||||
if(canonicalPath.startsWith(excludedPath))
|
if(canonicalPath.startsWith(excludedPath))
|
||||||
{
|
{
|
||||||
|
if(this->fileSaverOptions.verbose)
|
||||||
|
{
|
||||||
|
Logger::info() << "Skipped due to excluded path";
|
||||||
|
}
|
||||||
return SKIPPED;
|
return SKIPPED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileInfo.size() > 0)
|
bool mustFillContent = this->fileSaverOptions.fillPathsOnlyWithContent;
|
||||||
|
if(!mustFillContent)
|
||||||
|
{
|
||||||
|
mustFillContent = !this->fileSaverOptions.pathsOnly;
|
||||||
|
if(mustFillContent)
|
||||||
|
{
|
||||||
|
auto filetype = this->dbService->queryFileType(fileInfo.absolutePath());
|
||||||
|
if(filetype)
|
||||||
|
{
|
||||||
|
mustFillContent = filetype.value() == 'c';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fileInfo.size() > 0 && mustFillContent)
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QStringList args;
|
QStringList args;
|
||||||
@ -158,7 +176,7 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SaveFileResult result = this->dbService->saveFile(fileInfo, pageData);
|
SaveFileResult result = this->dbService->saveFile(fileInfo, pageData, this->fileSaverOptions.pathsOnly);
|
||||||
if(result == OK && processorReturnCode == OK_WASEMPTY)
|
if(result == OK && processorReturnCode == OK_WASEMPTY)
|
||||||
{
|
{
|
||||||
return OK_WASEMPTY;
|
return OK_WASEMPTY;
|
||||||
|
@ -12,6 +12,7 @@ FileScanWorker::FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &qu
|
|||||||
void FileScanWorker::run()
|
void FileScanWorker::run()
|
||||||
{
|
{
|
||||||
FileSaver saver{*this->dbService};
|
FileSaver saver{*this->dbService};
|
||||||
|
saver.setFileSaverOptions(this->fileSaverOptions);
|
||||||
auto paths = queue->dequeue(batchsize);
|
auto paths = queue->dequeue(batchsize);
|
||||||
for(QString &path : paths)
|
for(QString &path : paths)
|
||||||
{
|
{
|
||||||
@ -34,3 +35,8 @@ void FileScanWorker::run()
|
|||||||
}
|
}
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileScanWorker::setFileSaverOptions(FileSaverOptions options)
|
||||||
|
{
|
||||||
|
this->fileSaverOptions = options;
|
||||||
|
}
|
||||||
|
@ -15,12 +15,14 @@ class FileScanWorker : public QObject, public QRunnable
|
|||||||
protected:
|
protected:
|
||||||
SqliteDbService *dbService;
|
SqliteDbService *dbService;
|
||||||
ConcurrentQueue<QString> *queue;
|
ConcurrentQueue<QString> *queue;
|
||||||
|
FileSaverOptions fileSaverOptions;
|
||||||
int batchsize;
|
int batchsize;
|
||||||
std::atomic<bool> *stopToken;
|
std::atomic<bool> *stopToken;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &queue, int batchsize, std::atomic<bool> &stopToken);
|
FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &queue, int batchsize, std::atomic<bool> &stopToken);
|
||||||
void run() override;
|
void run() override;
|
||||||
|
void setFileSaverOptions(FileSaverOptions options);
|
||||||
signals:
|
signals:
|
||||||
void result(FileScanResult);
|
void result(FileScanResult);
|
||||||
void finished();
|
void finished();
|
||||||
|
@ -98,6 +98,7 @@ void Indexer::launchWorker(ConcurrentQueue<QString> &queue, int batchsize)
|
|||||||
FileScanWorker *runnable = new FileScanWorker(*this->db, queue, batchsize, this->workerCancellationToken);
|
FileScanWorker *runnable = new FileScanWorker(*this->db, queue, batchsize, this->workerCancellationToken);
|
||||||
connect(runnable, &FileScanWorker::result, this, &Indexer::processFileScanResult);
|
connect(runnable, &FileScanWorker::result, this, &Indexer::processFileScanResult);
|
||||||
connect(runnable, &FileScanWorker::finished, this, &Indexer::processFinishedWorker);
|
connect(runnable, &FileScanWorker::finished, this, &Indexer::processFinishedWorker);
|
||||||
|
runnable->setFileSaverOptions(this->fileSaverOptions);
|
||||||
++this->runningWorkers;
|
++this->runningWorkers;
|
||||||
QThreadPool::globalInstance()->start(runnable);
|
QThreadPool::globalInstance()->start(runnable);
|
||||||
}
|
}
|
||||||
|
@ -164,11 +164,15 @@ bool SqliteDbService::insertToFTS(bool useTrigrams, QSqlDatabase &db, int fileid
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveFileResult SqliteDbService::saveFile(QFileInfo fileInfo, QVector<PageData> &pageData)
|
SaveFileResult SqliteDbService::saveFile(QFileInfo fileInfo, QVector<PageData> &pageData, bool pathsOnly)
|
||||||
{
|
{
|
||||||
QString absPath = fileInfo.absoluteFilePath();
|
QString absPath = fileInfo.absoluteFilePath();
|
||||||
auto mtime = fileInfo.lastModified().toSecsSinceEpoch();
|
auto mtime = fileInfo.lastModified().toSecsSinceEpoch();
|
||||||
QChar fileType = fileInfo.isDir() ? 'd' : 'f';
|
QChar fileType = fileInfo.isDir() ? 'd' : 'c';
|
||||||
|
if(pathsOnly)
|
||||||
|
{
|
||||||
|
fileType = 'f';
|
||||||
|
}
|
||||||
|
|
||||||
QSqlDatabase db = dbFactory->forCurrentThread();
|
QSqlDatabase db = dbFactory->forCurrentThread();
|
||||||
QSqlQuery delQuery(db);
|
QSqlQuery delQuery(db);
|
||||||
@ -202,19 +206,23 @@ SaveFileResult SqliteDbService::saveFile(QFileInfo fileInfo, QVector<PageData> &
|
|||||||
return DBFAIL;
|
return DBFAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastid = inserterQuery.lastInsertId().toInt();
|
if(!pathsOnly)
|
||||||
if(!insertToFTS(false, db, lastid, pageData))
|
|
||||||
{
|
{
|
||||||
db.rollback();
|
int lastid = inserterQuery.lastInsertId().toInt();
|
||||||
Logger::error() << "Failed to insert data to FTS index " << Qt::endl;
|
if(!insertToFTS(false, db, lastid, pageData))
|
||||||
return DBFAIL;
|
{
|
||||||
}
|
db.rollback();
|
||||||
if(!insertToFTS(true, db, lastid, pageData))
|
Logger::error() << "Failed to insert data to FTS index " << Qt::endl;
|
||||||
{
|
return DBFAIL;
|
||||||
db.rollback();
|
}
|
||||||
Logger::error() << "Failed to insert data to FTS index " << Qt::endl;
|
if(!insertToFTS(true, db, lastid, pageData))
|
||||||
return DBFAIL;
|
{
|
||||||
|
db.rollback();
|
||||||
|
Logger::error() << "Failed to insert data to FTS index " << Qt::endl;
|
||||||
|
return DBFAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!db.commit())
|
if(!db.commit())
|
||||||
{
|
{
|
||||||
db.rollback();
|
db.rollback();
|
||||||
|
@ -19,7 +19,7 @@ class SqliteDbService
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SqliteDbService(DatabaseFactory &dbFactory);
|
SqliteDbService(DatabaseFactory &dbFactory);
|
||||||
SaveFileResult saveFile(QFileInfo fileInfo, QVector<PageData> &pageData);
|
SaveFileResult saveFile(QFileInfo fileInfo, QVector<PageData> &pageData, bool pathsOnly);
|
||||||
unsigned int getFiles(QVector<FileData> &results, QString wildCardPattern, int offset, int limit);
|
unsigned int getFiles(QVector<FileData> &results, QString wildCardPattern, int offset, int limit);
|
||||||
bool deleteFile(QString path);
|
bool deleteFile(QString path);
|
||||||
bool fileExistsInDatabase(QString path);
|
bool fileExistsInDatabase(QString path);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren