Allow configuration of the last-resort external command used to identify mime types

This commit is contained in:
Jean-Francois Dockes 2014-07-19 16:15:43 +02:00
parent c11453fc27
commit 46e924f3ea
2 changed files with 13 additions and 3 deletions

View File

@ -46,15 +46,21 @@ using namespace std;
/// current/interesting file types.
/// As a last resort we execute 'file' (except if forbidden by config)
static string mimetypefromdata(const string &fn, bool usfc)
static string mimetypefromdata(RclConfig *cfg, const string &fn, bool usfc)
{
// First try the internal identifying routine
string mime = idFile(fn.c_str());
#ifdef USE_SYSTEM_FILE_COMMAND
if (usfc && mime.empty()) {
// Last resort: use "file -i"
// Last resort: use "file -i", or its configured replacement.
vector<string> cmd = create_vector<string>(FILE_PROG) ("-i") (fn);
string scommand;
if (cfg->getConfParam("systemfilecommand", scommand)) {
stringToStrings(scommand, cmd);
cmd.push_back(fn);
}
string result;
if (!ExecCmd::backtick(cmd, result)) {
LOGERR(("mimetypefromdata: exec %s failed\n", FILE_PROG));
@ -164,7 +170,7 @@ string mimetype(const string &fn, const struct stat *stp,
// only do this if we have an actual file (as opposed to a pure
// name).
if (mtype.empty() && stp)
mtype = mimetypefromdata(fn, usfc);
mtype = mimetypefromdata(cfg, fn, usfc);
out:
return mtype;

View File

@ -189,6 +189,10 @@ iconsdir = @prefix@/share/recoll/images
# identification ? This may be useful, but will usually cause the
# indexation of many bogus 'text' files
usesystemfilecommand = 1
# Actual command to use as "file -i" workalike. xdg-mime works fine here.
# The file path will be added as a last parameter to the command line. If
# that's not what your preferred command would like, use an intermediary script
# systemfilecommand = xdg-mime query filetype
# Should we index the file names of files with mime types we don't
# know? (we can otherwise just ignore them)