index directory names

This commit is contained in:
dockes 2006-12-19 08:40:50 +00:00
parent 6127cbf028
commit 50b01c6ea4
10 changed files with 78 additions and 36 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.37 2006-12-16 15:30:02 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.38 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -248,7 +248,7 @@ string RclConfig::getMimeHandlerDef(const std::string &mtype)
{
string hs;
if (!mimeconf->get(mtype, hs, "index")) {
LOGDEB(("getMimeHandler: no handler for '%s'\n", mtype.c_str()));
LOGDEB1(("getMimeHandler: no handler for '%s'\n", mtype.c_str()));
}
return hs;
}

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.48 2006-12-16 15:30:32 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.49 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -344,7 +344,8 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
int abslen;
if (m_config->getConfParam("idxabsmlen", &abslen))
m_db.setAbstractParams(abslen, -1, -1);
return FsTreeWalker::FtwOk;
if (flg == FsTreeWalker::FtwDirReturn)
return FsTreeWalker::FtwOk;
}
// Check db up to date ? Doing this before file type
@ -363,7 +364,7 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
return FsTreeWalker::FtwOk;
}
FileInterner interner(fn, m_config, m_tmpdir);
FileInterner interner(fn, stp, m_config, m_tmpdir);
// File name transcoded to utf8 for indexation.
string charset = m_config->getDefCharset(true);
@ -427,8 +428,8 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
if (hadNullIpath == false) {
LOGDEB1(("Creating empty doc for file\n"));
Rcl::Doc fileDoc;
fileDoc.fmtime = doc.fmtime;
fileDoc.utf8fn = doc.utf8fn;
fileDoc.fmtime = ascdate;
fileDoc.utf8fn = utf8fn;
fileDoc.mimetype = interner.get_mimetype();
if (!m_db.add(fn, fileDoc, stp))
return FsTreeWalker::FtwError;

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: mimetype.cpp,v 1.18 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: mimetype.cpp,v 1.19 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -19,6 +19,8 @@ static char rcsid[] = "@(#$Id: mimetype.cpp,v 1.18 2006-12-11 14:50:53 dockes Ex
*/
#ifndef TEST_MIMETYPE
#include <sys/stat.h>
#include <ctype.h>
#include <string>
#include <list>
@ -104,8 +106,14 @@ static string mimetypefromdata(const string &fn, bool usfc)
/// Guess mime type, first from suffix, then from file data. We also
/// have a list of suffixes that we don't touch at all (ie: .jpg,
/// etc...)
string mimetype(const string &fn, RclConfig *cfg, bool usfc)
string mimetype(const string &fn, const struct stat *stp,
RclConfig *cfg, bool usfc)
{
if (S_ISDIR(stp->st_mode))
return "application/x-fsdirectory";
if (!S_ISREG(stp->st_mode))
return "application/x-fsspecial";
if (cfg == 0)
return "";
@ -140,7 +148,10 @@ string mimetype(const string &fn, RclConfig *cfg, bool usfc)
#else // TEST->
#include <stdio.h>
#include <sys/stat.h>
#include <iostream>
#include "debuglog.h"
@ -163,8 +174,13 @@ int main(int argc, const char **argv)
while (--argc > 0) {
string filename = *++argv;
struct stat st;
if (stat(filename.c_str(), &st)) {
fprintf(stderr, "Can't stat %s\n", filename.c_str());
continue;
}
cout << filename << " -> " <<
mimetype(filename, config, true) << endl;
mimetype(filename, &st, config, true) << endl;
}
return 0;

View File

@ -16,18 +16,19 @@
*/
#ifndef _MIMETYPE_H_INCLUDED_
#define _MIMETYPE_H_INCLUDED_
/* @(#$Id: mimetype.h,v 1.5 2006-01-30 11:15:27 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: mimetype.h,v 1.6 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
class RclConfig;
struct stat;
/**
* Try to determine a mime type for filename.
* This may imply more than matching the suffix, the name must be usable
* to actually access file data.
*/
string mimetype(const std::string &filename, RclConfig *cfg, bool usfc);
string mimetype(const std::string &filename, const struct stat *stp,
RclConfig *cfg, bool usfc);
#endif /* _MIMETYPE_H_INCLUDED_ */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.21 2006-12-16 15:39:54 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.22 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -111,7 +111,8 @@ void FileInterner::tmpcleanup()
// Handler==0 on return says we're in error, will be handled when calling
// internfile
FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
FileInterner::FileInterner(const std::string &f, const struct stat *stp,
RclConfig *cnf,
const string& td, const string *imime)
: m_cfg(cnf), m_fn(f), m_forPreview(imime?true:false), m_tdir(td)
{
@ -121,7 +122,7 @@ FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
// We need to run mime type identification in any case to check
// for a compressed file.
string l_mime = mimetype(m_fn, m_cfg, usfci);
string l_mime = mimetype(m_fn, stp, m_cfg, usfci);
// If identification fails, try to use the input parameter. This
// is then normally not a compressed type (it's the mime type from
@ -141,7 +142,8 @@ FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
LOGDEB1(("internfile: after ucomp: m_tdir %s, tfile %s\n",
m_tdir.c_str(), m_tfile.c_str()));
m_fn = m_tfile;
l_mime = mimetype(m_fn, m_cfg, usfci);
// Note: still using the original file's stat. right ?
l_mime = mimetype(m_fn, stp, m_cfg, usfci);
if (l_mime.empty() && imime)
l_mime = *imime;
}
@ -468,15 +470,20 @@ class DirWiper {
};
bool FileInterner::idocTempFile(TempFile& otemp, RclConfig *cnf,
const string& fn, const string& ipath,
const string& fn,
const string& ipath,
const string& mtype)
{
string tmpdir, reason;
if (!maketmpdir(tmpdir, reason))
return false;
DirWiper wiper(tmpdir);
FileInterner interner(fn, cnf, tmpdir, &mtype);
struct stat st;
if (stat(fn.c_str(), &st) < 0) {
LOGERR(("FileInterner::idocTempFile: can't stat [%s]\n", fn.c_str()));
return false;
}
FileInterner interner(fn, &st, cnf, tmpdir, &mtype);
interner.setTargetMType(mtype);
Rcl::Doc doc;
string mipath = ipath;

View File

@ -16,7 +16,7 @@
*/
#ifndef _INTERNFILE_H_INCLUDED_
#define _INTERNFILE_H_INCLUDED_
/* @(#$Id: internfile.h,v 1.9 2006-12-16 15:39:54 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: internfile.h,v 1.10 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <vector>
@ -31,6 +31,8 @@ namespace Rcl {
class Doc;
}
struct stat;
/**
* A class to convert a file into possibly multiple documents in internal
* representation.
@ -52,7 +54,8 @@ class FileInterner {
* mime type for the uncompressed version. This currently doubles up
* to indicate that this object is for previewing (not indexing).
*/
FileInterner(const string &fn, RclConfig *cnf, const string& td,
FileInterner(const string &fn, const struct stat *stp,
RclConfig *cnf, const string& td,
const string *mtype = 0);
~FileInterner();

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.20 2006-12-15 12:40:02 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.21 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -38,16 +38,18 @@ using namespace std;
/** Create internal handler object appropriate for given mime type */
static Dijon::Filter *mhFactory(const string &mime)
{
if (!stringlowercmp("text/plain", mime))
return new MimeHandlerText("text/plain");
else if (!stringlowercmp("text/html", mime))
return new MimeHandlerHtml("text/html");
else if (!stringlowercmp("text/x-mail", mime))
return new MimeHandlerMbox("text/x-mail");
else if (!stringlowercmp("message/rfc822", mime))
return new MimeHandlerMail("message/rfc822");
string lmime(mime);
stringtolower(lmime);
if ("text/plain" == lmime)
return new MimeHandlerText(lmime);
else if ("text/html" == lmime)
return new MimeHandlerHtml(lmime);
else if ("text/x-mail" == lmime)
return new MimeHandlerMbox(lmime);
else if ("message/rfc822" == lmime)
return new MimeHandlerMail(lmime);
else
return new MimeHandlerUnknown("application/octet-stream");
return new MimeHandlerUnknown(lmime);
}
/**

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.10 2006-12-14 13:53:43 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.11 2006-12-19 08:40:50 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -19,6 +19,7 @@ static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.10 2006-12-14 13:53:43 dockes E
*/
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>
#include <list>
#include <utility>
@ -460,7 +461,16 @@ class LoadThread : public QThread {
*statusp = -1;
return;
}
FileInterner interner(filename, rclconfig, tmpdir, mtype);
struct stat st;
if (stat(filename.c_str(), &st) < 0) {
LOGERR(("Preview: can't stat [%s]\n", filename.c_str()));
QMessageBox::critical(0, "Recoll",
Preview::tr("File does not exist"));
*statusp = -1;
return;
}
FileInterner interner(filename, &st, rclconfig, tmpdir, mtype);
try {
FileInterner::Status ret = interner.internfile(*out, ipath);
if (ret == FileInterner::FIDone || ret == FileInterner::FIAgain) {

View File

@ -1,4 +1,4 @@
# @(#$Id: mimeconf,v 1.19 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes
# @(#$Id: mimeconf,v 1.20 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes
# Recoll : associations of mime types to processing filters.
# There are different sections for decompression, 'interning' for indexing
@ -67,6 +67,7 @@ application/vnd.sun.xml.impress.template = presentation
application/vnd.sun.xml.writer = wordprocessing
application/vnd.sun.xml.writer.global = wordprocessing
application/vnd.sun.xml.writer.template = wordprocessing
application/x-fsdirectory = folder
application/x-dvi = document
audio/mpeg = sownd
image/jpeg = image

View File

@ -1,4 +1,4 @@
# @(#$Id: mimeview,v 1.1 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes
# @(#$Id: mimeview,v 1.2 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes
## ##########################################
# External viewers, launched by the recoll GUI when you click on a result
@ -20,6 +20,7 @@ application/vnd.sun.xml.math = openoffice %f
application/vnd.sun.xml.writer = openoffice %f
application/vnd.sun.xml.writer.global = openoffice %f
application/vnd.sun.xml.writer.template = openoffice %f
application/x-fsdirectory = rox %f
application/x-dvi = xdvi %f
audio/mpeg = xmms %f
image/jpeg = xv %f