|
QtPass 2.0.0
Developer documentation
|
Full-text search over a password store without pass grep: every .gpg file is decrypted with gpg on a worker thread and its lines matched against a QRegularExpression. Only the newest search may report; a search started while another runs asks that one to stop and supersedes it. More...
#include <nativegrep.h>
Classes | |
| struct | Worker |
Signals | |
| void | finished (const QList< QPair< QString, QStringList > > &results) |
| The newest search is over. | |
Public Member Functions | |
| NativeGrep (QObject *parent=nullptr) | |
| Create a searcher. | |
| ~NativeGrep () override | |
| Interrupt running searches and wait up to five seconds for them. | |
| void | search (const QString &pattern, bool caseInsensitive, const QString &gpgExe, const QString &storeDir, const QProcessEnvironment &env) |
| Start a search; finished() follows asynchronously, also for an empty or invalid pattern (with no results). | |
| void | cancel () |
| Ask running searches to stop without waiting for them: the walk ends at the next file and a gpg that is decrypting is terminated by its own worker thread. | |
Static Public Member Functions | |
| static auto | isMoreMarker (const QString &line) -> bool |
| Whether a line in a result is the marker for "more matches in
this entry" rather than a match. | |
| static auto | isStoppedMarker (const QPair< QString, QStringList > &result) -> bool |
| Whether a result is the marker for "the search stopped at
kMaxMatches, more entries were not searched". | |
| static auto | matchFile (const QProcessEnvironment &env, const QString &gpgExe, const QString &filePath, const QRegularExpression &rx, const std::atomic_bool *cancel=nullptr) -> QStringList |
Decrypt one .gpg file and return its trimmed lines matching rx. | |
| static auto | scanStore (const QProcessEnvironment &env, const QString &gpgExe, const QString &storeDir, const QRegularExpression &rx, const std::atomic_bool *cancel=nullptr) -> QList< QPair< QString, QStringList > > |
Walk storeDir, decrypt every .gpg file and collect the matches. | |
Static Public Attributes | |
| static constexpr int | kMaxMatchesPerEntry = 100 |
| Most matching lines taken from one entry. | |
| static constexpr int | kMaxMatches = 10000 |
| Most matching lines a search collects over the whole store. | |
| static constexpr qsizetype | kMaxPreviewLength = 200 |
| Longest preview of a matching line, in UTF-16 code units. | |
Private Attributes | |
| int | m_seq = 0 |
| Number of the newest search. A worker reports through finished() only when its own number still equals this. | |
| QList< Worker > | m_workers |
| Searches still running, superseded ones included. | |
Full-text search over a password store without pass grep: every .gpg file is decrypted with gpg on a worker thread and its lines matched against a QRegularExpression. Only the newest search may report; a search started while another runs asks that one to stop and supersedes it.
Definition at line 31 of file nativegrep.h.
|
explicit |
Create a searcher.
| parent | Owner; results are delivered on its thread. |
Definition at line 21 of file nativegrep.cpp.
|
override |
Interrupt running searches and wait up to five seconds for them.
Definition at line 23 of file nativegrep.cpp.
| void NativeGrep::cancel | ( | ) |
Ask running searches to stop without waiting for them: the walk ends at the next file and a gpg that is decrypting is terminated by its own worker thread.
Definition at line 230 of file nativegrep.cpp.
|
signal |
The newest search is over.
| results | (entry, matching lines) pairs. |
|
inlinestaticnodiscard |
Whether a line in a result is the marker for "more matches in this entry" rather than a match.
A match is a trimmed, non-empty line, so an empty one can only be the marker, which matchFile() and scanStore() put last. Not a match: not counted, not content to hide.
| line | A line of a result. |
Definition at line 80 of file nativegrep.h.
|
inlinestaticnodiscard |
Whether a result is the marker for "the search stopped at kMaxMatches, more entries were not searched".
No entry has an empty name, so a result without one can only be the marker, which scanStore() puts last.
| result | A result. |
Definition at line 94 of file nativegrep.h.
|
static |
Decrypt one .gpg file and return its trimmed lines matching rx.
Decrypt one .gpg file and return lines matching rx.
| env | Environment for gpg. |
| gpgExe | The gpg executable. |
| filePath | The encrypted file. |
| rx | The pattern. |
| cancel | When set, gpg is not started, or is terminated while it runs; nullptr to run to completion. |
Definition at line 41 of file nativegrep.cpp.
|
static |
Walk storeDir, decrypt every .gpg file and collect the matches.
Walk the store, decrypt every .gpg file, collect matches.
| env | Environment for gpg. |
| gpgExe | The gpg executable. |
| storeDir | The store. |
| rx | The pattern. |
| cancel | Stops the walk and the running gpg when set; nullptr to rely on QThread::isInterruptionRequested() alone. |
Definition at line 107 of file nativegrep.cpp.
| void NativeGrep::search | ( | const QString & | pattern, |
| bool | caseInsensitive, | ||
| const QString & | gpgExe, | ||
| const QString & | storeDir, | ||
| const QProcessEnvironment & | env ) |
Start a search; finished() follows asynchronously, also for an empty or invalid pattern (with no results).
Start a search on a worker thread.
| pattern | PCRE pattern. |
| caseInsensitive | Match regardless of case. |
| gpgExe | The gpg executable (a wsl prefix routes paths through wslpath). |
| storeDir | The store to walk. |
| env | Environment for gpg (GNUPGHOME and friends). |
Results are emitted on the owner's thread via QMetaObject::invokeMethod. A sequence counter discards results from superseded searches; the previous search is asked to stop but not waited for, since blocking the UI thread while gpg decrypts would freeze the interface.
Definition at line 160 of file nativegrep.cpp.
|
staticconstexpr |
Most matching lines a search collects over the whole store.
The search stops once it has this many; the window says so.
Definition at line 55 of file nativegrep.h.
|
staticconstexpr |
Most matching lines taken from one entry.
A compressed entry can expand into millions of lines within the plaintext limit, each a result and a row in the results list; past this many, the entry gets one line saying there are more.
Definition at line 48 of file nativegrep.h.
|
staticconstexpr |
Longest preview of a matching line, in UTF-16 code units.
A result shows where the pattern matched, not the line; a single line can be most of an entry's 64 MiB plaintext, and 10000 such copies would not fit in memory. A longer line is shown as a window of this many code units around the match (up to two more, one per edge, to keep a surrogate pair whole), "…" where the line goes on. A sequence of several code points (a ZWJ emoji, a flag) can still be cut between them.
Definition at line 68 of file nativegrep.h.
|
private |
Number of the newest search. A worker reports through finished() only when its own number still equals this.
Definition at line 179 of file nativegrep.h.
|
private |
Searches still running, superseded ones included.
Definition at line 181 of file nativegrep.h.