fix rare case where indexed file could not be previewed because of change in file identification config param

This commit is contained in:
dockes 2005-11-14 09:59:17 +00:00
parent 456e6ee183
commit b31976558a
3 changed files with 45 additions and 8 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.7 2005-11-10 08:47:49 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.8 2005-11-14 09:59:17 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include <unistd.h>
#include <sys/types.h>
@ -83,7 +83,7 @@ void FileInterner::tmpcleanup()
// Handler==0 on return says we're in error
FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
const string& td)
const string& td, const string *imime)
: fn(f), config(cnf), tdir(td), handler(0)
{
// Note that we are actually going to access the file, so that it's ok
@ -97,7 +97,14 @@ FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
usfci = atoi(usfc.c_str()) ? 1 : 0;
LOGDEB1(("FileInterner::FileInterner: usfci now %d\n", usfci));
// We need to run mime type identification in any case to check
// for a compressed file.
mime = mimetype(fn, config->getMimeMap(), usfci);
// If identification fails, try to use the input parameter. Note that this
// is normally not a compressed type (it's the mime type from the db)
if (mime.empty() && imime)
mime = *imime;
if (mime.empty()) {
// No mime type: not listed in our map, or present in stop list
LOGDEB(("FileInterner::FileInterner: (no mime) [%s]\n", fn.c_str()));
@ -116,6 +123,8 @@ FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
tdir.c_str(), tfile.c_str()));
fn = tfile;
mime = mimetype(fn, config->getMimeMap(), usfci);
if (mime.empty() && imime)
mime = *imime;
if (mime.empty()) {
// No mime type ?? pass on.
LOGDEB(("internfile: (no mime) [%s]\n", fn.c_str()));

View File

@ -1,6 +1,6 @@
#ifndef _INTERNFILE_H_INCLUDED_
#define _INTERNFILE_H_INCLUDED_
/* @(#$Id: internfile.h,v 1.3 2005-03-25 09:40:27 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: internfile.h,v 1.4 2005-11-14 09:59:17 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
@ -9,7 +9,8 @@
class MimeHandler;
/// Turn external file into internal representation, according to mime type etc
/// Turn external file into internal representation, according to mime
/// type etc
class FileInterner {
string fn;
RclConfig *config;
@ -21,10 +22,36 @@ class FileInterner {
void tmpcleanup();
public:
FileInterner(const std::string &f, RclConfig *cnf, const string& td);
/**
* Identify and possibly decompress file, create adequate handler
* @param fn file name
* @param cnf Recoll configuration
* @param td temporary directory to use as working space for possible
* decompression
* @param mimetype mime type if known. For a compressed file this is the
* mime type for the uncompressed version.
*/
FileInterner(const std::string &fn, RclConfig *cnf, const string& td,
const std::string *mtype = 0);
~FileInterner();
/// Return values for internfile()
enum Status {FIError, FIDone, FIAgain};
/**
* Turn file or file part into Recoll document.
*
* For multidocument files (ie: mail folder), this must be called multiple
* times to retrieve the subdocuments
* @param doc output document
* @param ipath internal path. If set by caller, the specified subdoc will
* be returned. Else the next document according to current state will
* be returned, and the internal path will be set.
* @return FIError and FIDone are self-explanatory. If FIAgain is returned,
* this is a multi-document file, with more subdocs, and internfile()
* should be called again to get the following one(s).
*/
Status internfile(Rcl::Doc& doc, string &ipath);
};

View File

@ -502,7 +502,8 @@ void RecollMain::startAdvSearch(Rcl::AdvSearchData sdata)
reslist_current = -1;
reslist_winfirst = -1;
if (!rcldb->setQuery(sdata, stemlang))
if (!rcldb->setQuery(sdata, dostem ?
Rcl::Db::QO_STEM : Rcl::Db::QO_NONE, stemlang))
return;
curPreview = 0;
listNextPB_clicked();
@ -570,10 +571,10 @@ void RecollMain::startPreview(int docnum)
qApp->processEvents();
Rcl::Doc fdoc;
FileInterner interner(fn, rclconfig, tmpdir);
FileInterner interner(fn, rclconfig, tmpdir, &doc.mimetype);
if (interner.internfile(fdoc, doc.ipath) != FileInterner::FIDone) {
QMessageBox::warning(0, "Recoll",
QString("Can't turn doc into internal rep ") +
QString("Can't turn doc into internal rep for ") +
doc.mimetype.c_str());
return;
}