add onlyNames config variable for filtering file names
This commit is contained in:
+22
-199
@@ -14,7 +14,7 @@
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
#ifndef TEST_RCLCONFIG
|
||||
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -186,6 +186,7 @@ RclConfig::RclConfig(const RclConfig &r)
|
||||
m_stpsuffstate(this, {"noContentSuffixes", "noContentSuffixes+",
|
||||
"noContentSuffixes-"}),
|
||||
m_skpnstate(this, {"skippedNames", "skippedNames+", "skippedNames-"}),
|
||||
m_onlnstate(this, "onlyNames"),
|
||||
m_rmtstate(this, "indexedmimetypes"),
|
||||
m_xmtstate(this, "excludedmimetypes"),
|
||||
m_mdrstate(this, "metadatacmds")
|
||||
@@ -198,6 +199,7 @@ RclConfig::RclConfig(const string *argcnf)
|
||||
m_stpsuffstate(this, {"noContentSuffixes", "noContentSuffixes+",
|
||||
"noContentSuffixes-"}),
|
||||
m_skpnstate(this, {"skippedNames", "skippedNames+", "skippedNames-"}),
|
||||
m_onlnstate(this, "onlyNames"),
|
||||
m_rmtstate(this, "indexedmimetypes"),
|
||||
m_xmtstate(this, "excludedmimetypes"),
|
||||
m_mdrstate(this, "metadatacmds")
|
||||
@@ -1539,6 +1541,14 @@ vector<string>& RclConfig::getSkippedNames()
|
||||
return m_skpnlist;
|
||||
}
|
||||
|
||||
vector<string>& RclConfig::getOnlyNames()
|
||||
{
|
||||
if (m_onlnstate.needrecompute()) {
|
||||
stringToStrings(m_onlnstate.getvalue(), m_onlnlist);
|
||||
}
|
||||
return m_onlnlist;
|
||||
}
|
||||
|
||||
vector<string> RclConfig::getSkippedPaths() const
|
||||
{
|
||||
vector<string> skpl;
|
||||
@@ -1680,15 +1690,15 @@ bool RclConfig::getUncompressor(const string &mtype, vector<string>& cmd) const
|
||||
}
|
||||
|
||||
static const char blurb0[] =
|
||||
"# The system-wide configuration files for recoll are located in:\n"
|
||||
"# %s\n"
|
||||
"# The default configuration files are commented, you should take a look\n"
|
||||
"# at them for an explanation of what can be set (you could also take a look\n"
|
||||
"# at the manual instead).\n"
|
||||
"# Values set in this file will override the system-wide values for the file\n"
|
||||
"# with the same name in the central directory. The syntax for setting\n"
|
||||
"# values is identical.\n"
|
||||
;
|
||||
"# The system-wide configuration files for recoll are located in:\n"
|
||||
"# %s\n"
|
||||
"# The default configuration files are commented, you should take a look\n"
|
||||
"# at them for an explanation of what can be set (you could also take a look\n"
|
||||
"# at the manual instead).\n"
|
||||
"# Values set in this file will override the system-wide values for the file\n"
|
||||
"# with the same name in the central directory. The syntax for setting\n"
|
||||
"# values is identical.\n"
|
||||
;
|
||||
// We just use path_max to print the path to /usr/share/recoll/examples
|
||||
// inside the config file. At worse, the text is truncated (using
|
||||
// snprintf). But 4096 should be enough :)
|
||||
@@ -1799,6 +1809,7 @@ void RclConfig::initFrom(const RclConfig& r)
|
||||
m_xattrtofld = r.m_xattrtofld;
|
||||
m_maxsufflen = r.m_maxsufflen;
|
||||
m_skpnlist = r.m_skpnlist;
|
||||
m_onlnlist = r.m_onlnlist;
|
||||
m_stopsuffixes = r.m_stopsuffixes;
|
||||
m_defcharset = r.m_defcharset;
|
||||
m_restrictMTypes = r.m_restrictMTypes;
|
||||
@@ -1829,196 +1840,8 @@ void RclConfig::initParamStale(ConfNull *cnf, ConfNull *mimemap)
|
||||
m_oldstpsuffstate.init(mimemap);
|
||||
m_stpsuffstate.init(cnf);
|
||||
m_skpnstate.init(cnf);
|
||||
m_onlnstate.init(cnf);
|
||||
m_rmtstate.init(cnf);
|
||||
m_xmtstate.init(cnf);
|
||||
m_mdrstate.init(cnf);
|
||||
}
|
||||
|
||||
#else // -> Test
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "rclinit.h"
|
||||
#include "rclconfig.h"
|
||||
#include "cstr.h"
|
||||
|
||||
static char *thisprog;
|
||||
|
||||
static char usage [] = "\n"
|
||||
"-c: check a few things in the configuration files\n"
|
||||
"[-s subkey] -q param : query parameter value\n"
|
||||
"-f : print some field data\n"
|
||||
" : default: print parameters\n"
|
||||
|
||||
;
|
||||
static void
|
||||
Usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s: usage: %s\n", thisprog, usage);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int op_flags;
|
||||
#define OPT_MOINS 0x1
|
||||
#define OPT_s 0x2
|
||||
#define OPT_q 0x4
|
||||
#define OPT_c 0x8
|
||||
#define OPT_f 0x10
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
string pname, skey;
|
||||
|
||||
thisprog = argv[0];
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0 && **argv == '-') {
|
||||
(*argv)++;
|
||||
if (!(**argv))
|
||||
/* Cas du "adb - core" */
|
||||
Usage();
|
||||
while (**argv)
|
||||
switch (*(*argv)++) {
|
||||
case 'c': op_flags |= OPT_c; break;
|
||||
case 'f': op_flags |= OPT_f; break;
|
||||
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
|
||||
skey = *(++argv);
|
||||
argc--;
|
||||
goto b1;
|
||||
case 'q': op_flags |= OPT_q; if (argc < 2) Usage();
|
||||
pname = *(++argv);
|
||||
argc--;
|
||||
goto b1;
|
||||
default: Usage(); break;
|
||||
}
|
||||
b1: argc--; argv++;
|
||||
}
|
||||
|
||||
if (argc != 0)
|
||||
Usage();
|
||||
|
||||
string reason;
|
||||
RclConfig *config = recollinit(0, 0, 0, reason);
|
||||
if (config == 0 || !config->ok()) {
|
||||
cerr << "Configuration problem: " << reason << endl;
|
||||
exit(1);
|
||||
}
|
||||
if (op_flags & OPT_s)
|
||||
config->setKeyDir(skey);
|
||||
if (op_flags & OPT_q) {
|
||||
string value;
|
||||
if (!config->getConfParam(pname, value)) {
|
||||
fprintf(stderr, "getConfParam failed for [%s]\n", pname.c_str());
|
||||
exit(1);
|
||||
}
|
||||
printf("[%s] -> [%s]\n", pname.c_str(), value.c_str());
|
||||
} else if (op_flags & OPT_f) {
|
||||
set<string> stored = config->getStoredFields();
|
||||
set<string> indexed = config->getIndexedFields();
|
||||
cout << "Stored fields: ";
|
||||
for (set<string>::const_iterator it = stored.begin();
|
||||
it != stored.end(); it++) {
|
||||
cout << "[" << *it << "] ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Indexed fields: ";
|
||||
for (set<string>::const_iterator it = indexed.begin();
|
||||
it != indexed.end(); it++) {
|
||||
const FieldTraits *ftp;
|
||||
config->getFieldTraits(*it, &ftp);
|
||||
if (ftp)
|
||||
cout << "[" << *it << "]" << " -> [" << ftp->pfx << "] ";
|
||||
else
|
||||
cout << "[" << *it << "]" << " -> [" << "(none)" << "] ";
|
||||
|
||||
}
|
||||
cout << endl;
|
||||
} else if (op_flags & OPT_c) {
|
||||
// Checking the configuration consistency
|
||||
|
||||
// Find and display category names
|
||||
vector<string> catnames;
|
||||
config->getMimeCategories(catnames);
|
||||
cout << "Categories: ";
|
||||
for (vector<string>::const_iterator it = catnames.begin();
|
||||
it != catnames.end(); it++) {
|
||||
cout << *it << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
// Compute union of all types from each category. Check that there
|
||||
// are no duplicates while we are at it.
|
||||
set<string> allmtsfromcats;
|
||||
for (vector<string>::const_iterator it = catnames.begin();
|
||||
it != catnames.end(); it++) {
|
||||
vector<string> cts;
|
||||
config->getMimeCatTypes(*it, cts);
|
||||
for (vector<string>::const_iterator it1 = cts.begin();
|
||||
it1 != cts.end(); it1++) {
|
||||
// Already in map -> duplicate
|
||||
if (allmtsfromcats.find(*it1) != allmtsfromcats.end()) {
|
||||
cout << "Duplicate: [" << *it1 << "]" << endl;
|
||||
}
|
||||
allmtsfromcats.insert(*it1);
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve complete list of mime types
|
||||
vector<string> mtypes = config->getAllMimeTypes();
|
||||
|
||||
// And check that each mime type is found in exactly one category
|
||||
for (vector<string>::const_iterator it = mtypes.begin();
|
||||
it != mtypes.end(); it++) {
|
||||
if (allmtsfromcats.find(*it) == allmtsfromcats.end()) {
|
||||
cout << "Not found in catgs: [" << *it << "]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// List mime types not in mimeview
|
||||
for (vector<string>::const_iterator it = mtypes.begin();
|
||||
it != mtypes.end(); it++) {
|
||||
if (config->getMimeViewerDef(*it, "", false).empty()) {
|
||||
cout << "No viewer: [" << *it << "]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Check that each mime type has an indexer
|
||||
for (vector<string>::const_iterator it = mtypes.begin();
|
||||
it != mtypes.end(); it++) {
|
||||
if (config->getMimeHandlerDef(*it, false).empty()) {
|
||||
cout << "No filter: [" << *it << "]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Check that each mime type has a defined icon
|
||||
for (vector<string>::const_iterator it = mtypes.begin();
|
||||
it != mtypes.end(); it++) {
|
||||
if (config->getMimeIconPath(*it, "") == "document") {
|
||||
cout << "No or generic icon: [" << *it << "]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
config->setKeyDir(cstr_null);
|
||||
vector<string> names = config->getConfNames();
|
||||
for (vector<string>::iterator it = names.begin();
|
||||
it != names.end();it++) {
|
||||
string value;
|
||||
config->getConfParam(*it, value);
|
||||
cout << *it << " -> [" << value << "]" << endl;
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif // TEST_RCLCONFIG
|
||||
|
||||
|
||||
@@ -214,6 +214,9 @@ class RclConfig {
|
||||
|
||||
/** Get list of skipped file names for current keydir */
|
||||
vector<string>& getSkippedNames();
|
||||
/** Get list of file name filters for current keydir (only those
|
||||
names indexed) */
|
||||
vector<string>& getOnlyNames();
|
||||
|
||||
/** Get list of skipped paths patterns. Doesn't depend on the keydir */
|
||||
vector<string> getSkippedPaths() const;
|
||||
@@ -390,9 +393,14 @@ class RclConfig {
|
||||
ParamStale m_stpsuffstate;
|
||||
vector<string> m_stopsuffvec;
|
||||
|
||||
// skippedNames state
|
||||
ParamStale m_skpnstate;
|
||||
vector<string> m_skpnlist;
|
||||
|
||||
// onlyNames state
|
||||
ParamStale m_onlnstate;
|
||||
vector<string> m_onlnlist;
|
||||
|
||||
// Original current working directory. Set once at init before we do any
|
||||
// chdir'ing and used for converting user args to absolute paths.
|
||||
static string o_origcwd;
|
||||
|
||||
Reference in New Issue
Block a user