Add support for indexing symlinks as such. Use inode/directory instead of application/x-fsdirectory as directory mime type. Fix stat/lstat usage in places (wipedir)
This commit is contained in:
@@ -31,7 +31,8 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
static bool urltopath(const Rcl::Doc& idoc, string& fn, struct stat& st)
|
||||
static bool urltopath(RclConfig* cnf,
|
||||
const Rcl::Doc& idoc, string& fn, struct stat& st)
|
||||
{
|
||||
// The url has to be like file://
|
||||
if (idoc.url.find(cstr_fileu) != 0) {
|
||||
@@ -40,7 +41,11 @@ static bool urltopath(const Rcl::Doc& idoc, string& fn, struct stat& st)
|
||||
return false;
|
||||
}
|
||||
fn = idoc.url.substr(7, string::npos);
|
||||
if (stat(fn.c_str(), &st) < 0) {
|
||||
cnf->setKeyDir(path_getfather(fn));
|
||||
bool follow = false;
|
||||
cnf->getConfParam("followLinks", &follow);
|
||||
|
||||
if ((follow ? stat(fn.c_str(), &st) : lstat(fn.c_str(), &st))< 0) {
|
||||
LOGERR(("FSDocFetcher::fetch: stat errno %d for [%s]\n",
|
||||
errno, fn.c_str()));
|
||||
return false;
|
||||
@@ -51,7 +56,7 @@ static bool urltopath(const Rcl::Doc& idoc, string& fn, struct stat& st)
|
||||
bool FSDocFetcher::fetch(RclConfig* cnf, const Rcl::Doc& idoc, RawDoc& out)
|
||||
{
|
||||
string fn;
|
||||
if (!urltopath(idoc, fn, out.st))
|
||||
if (!urltopath(cnf, idoc, fn, out.st))
|
||||
return false;
|
||||
out.kind = RawDoc::RDK_FILENAME;
|
||||
out.data = fn;
|
||||
@@ -62,7 +67,7 @@ bool FSDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
|
||||
{
|
||||
string fn;
|
||||
struct stat st;
|
||||
if (!urltopath(idoc, fn, st))
|
||||
if (!urltopath(cnf, idoc, fn, st))
|
||||
return false;
|
||||
FsIndexer::makesig(&st, sig);
|
||||
return true;
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#ifndef _fsindexer_h_included_
|
||||
#define _fsindexer_h_included_
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "indexer.h"
|
||||
|
||||
@@ -122,9 +122,11 @@ string mimetype(const string &fn, const struct stat *stp,
|
||||
// 'mime:' filter with the query language, but it's not work
|
||||
// changing (would force a reindex).
|
||||
if (S_ISDIR(stp->st_mode))
|
||||
return "application/x-fsdirectory";
|
||||
return "inode/directory";
|
||||
if (S_ISLNK(stp->st_mode))
|
||||
return "inode/symlink";
|
||||
if (!S_ISREG(stp->st_mode))
|
||||
return "application/x-fsspecial";
|
||||
return "inode/x-fsspecial";
|
||||
}
|
||||
|
||||
string mtype;
|
||||
@@ -191,7 +193,7 @@ int main(int argc, const char **argv)
|
||||
while (--argc > 0) {
|
||||
string filename = *++argv;
|
||||
struct stat st;
|
||||
if (stat(filename.c_str(), &st)) {
|
||||
if (lstat(filename.c_str(), &st)) {
|
||||
fprintf(stderr, "Can't stat %s\n", filename.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user