Allow configuration of the last-resort external command used to identify mime types
This commit is contained in:
parent
c11453fc27
commit
46e924f3ea
@ -46,15 +46,21 @@ using namespace std;
|
|||||||
/// current/interesting file types.
|
/// current/interesting file types.
|
||||||
/// As a last resort we execute 'file' (except if forbidden by config)
|
/// 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
|
// First try the internal identifying routine
|
||||||
string mime = idFile(fn.c_str());
|
string mime = idFile(fn.c_str());
|
||||||
|
|
||||||
#ifdef USE_SYSTEM_FILE_COMMAND
|
#ifdef USE_SYSTEM_FILE_COMMAND
|
||||||
if (usfc && mime.empty()) {
|
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);
|
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;
|
string result;
|
||||||
if (!ExecCmd::backtick(cmd, result)) {
|
if (!ExecCmd::backtick(cmd, result)) {
|
||||||
LOGERR(("mimetypefromdata: exec %s failed\n", FILE_PROG));
|
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
|
// only do this if we have an actual file (as opposed to a pure
|
||||||
// name).
|
// name).
|
||||||
if (mtype.empty() && stp)
|
if (mtype.empty() && stp)
|
||||||
mtype = mimetypefromdata(fn, usfc);
|
mtype = mimetypefromdata(cfg, fn, usfc);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return mtype;
|
return mtype;
|
||||||
|
|||||||
@ -189,6 +189,10 @@ iconsdir = @prefix@/share/recoll/images
|
|||||||
# identification ? This may be useful, but will usually cause the
|
# identification ? This may be useful, but will usually cause the
|
||||||
# indexation of many bogus 'text' files
|
# indexation of many bogus 'text' files
|
||||||
usesystemfilecommand = 1
|
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
|
# Should we index the file names of files with mime types we don't
|
||||||
# know? (we can otherwise just ignore them)
|
# know? (we can otherwise just ignore them)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user