Try to give possible explanations when opening a preview fails

This commit is contained in:
Jean-Francois Dockes
2019-06-15 19:21:52 +02:00
parent e7ba872404
commit dca18bc585
12 changed files with 574 additions and 479 deletions
+3 -2
View File
@@ -77,7 +77,8 @@ bool EXEDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
}
// Lookup bckid in the config and create an appropriate fetcher.
EXEDocFetcher *exeDocFetcherMake(RclConfig *config, const string& bckid)
std::unique_ptr<EXEDocFetcher> exeDocFetcherMake(RclConfig *config,
const string& bckid)
{
// The config we only read once, not gonna change.
static ConfSimple *bconf;
@@ -122,5 +123,5 @@ EXEDocFetcher *exeDocFetcherMake(RclConfig *config, const string& bckid)
" not found in exec path or filters dir\n");
return 0;
}
return new EXEDocFetcher(m);
return std::unique_ptr<EXEDocFetcher>(new EXEDocFetcher(m));
}
+6 -2
View File
@@ -17,6 +17,7 @@
#ifndef _EXEFETCHER_H_INCLUDED_
#define _EXEFETCHER_H_INCLUDED_
#include <memory>
#include "fetcher.h"
class RclConfig;
@@ -35,6 +36,7 @@ class RclConfig;
* query time for previewing and opening the document.
*/
class EXEDocFetcher : public DocFetcher {
public:
class Internal;
EXEDocFetcher(const Internal&);
virtual ~EXEDocFetcher() {}
@@ -42,12 +44,14 @@ class EXEDocFetcher : public DocFetcher {
virtual bool fetch(RclConfig* cnf, const Rcl::Doc& idoc, RawDoc& out);
/** Calls stat to retrieve file signature data */
virtual bool makesig(RclConfig* cnf, const Rcl::Doc& idoc,std::string& sig);
friend EXEDocFetcher *exeDocFetcherMake(RclConfig *, const std::string&);
friend std::unique_ptr<EXEDocFetcher>
exeDocFetcherMake(RclConfig *, const std::string&);
private:
Internal *m;
};
// Lookup bckid in the config and create an appropriate fetcher.
EXEDocFetcher *exeDocFetcherMake(RclConfig *config, const std::string& bckid);
std::unique_ptr<EXEDocFetcher> exeDocFetcherMake(RclConfig *config,
const std::string& bckid);
#endif /* _EXEFETCHER_H_INCLUDED_ */
+8 -5
View File
@@ -16,6 +16,8 @@
*/
#include "autoconfig.h"
#include <memory>
#include "log.h"
#include "rclconfig.h"
#include "fetcher.h"
@@ -23,22 +25,23 @@
#include "webqueuefetcher.h"
#include "exefetcher.h"
DocFetcher *docFetcherMake(RclConfig *config, const Rcl::Doc& idoc)
std::unique_ptr<DocFetcher> docFetcherMake(RclConfig *config,
const Rcl::Doc& idoc)
{
if (idoc.url.empty()) {
LOGERR("docFetcherMakeg:: no url in doc!\n" );
return 0;
return std::unique_ptr<DocFetcher>();
}
string backend;
idoc.getmeta(Rcl::Doc::keybcknd, &backend);
if (backend.empty() || !backend.compare("FS")) {
return new FSDocFetcher;
return std::unique_ptr<DocFetcher>(new FSDocFetcher);
#ifndef DISABLE_WEB_INDEXER
} else if (!backend.compare("BGL")) {
return new WQDocFetcher;
return std::unique_ptr<DocFetcher>(new WQDocFetcher);
#endif
} else {
DocFetcher *f = exeDocFetcherMake(config, backend);
std::unique_ptr<DocFetcher> f(exeDocFetcherMake(config, backend));
if (!f) {
LOGERR("DocFetcherFactory: unknown backend [" << backend << "]\n");
}
+13 -7
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2012 J.F.Dockes
/* Copyright (C) 2012-2019 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -19,6 +19,7 @@
#include "safesysstat.h"
#include <string>
#include <memory>
#include "rcldoc.h"
@@ -45,12 +46,12 @@ class RclConfig;
class DocFetcher {
public:
/** A RawDoc is the data for a document-holding entity either as a
memory block, or pointed to by a file name */
memory block, or pointed to by a file name */
struct RawDoc {
enum RawDocKind {RDK_FILENAME, RDK_DATA, RDK_DATADIRECT};
RawDocKind kind;
std::string data; // Doc data or file name
struct stat st; // Only used if RDK_FILENAME
enum RawDocKind {RDK_FILENAME, RDK_DATA, RDK_DATADIRECT};
RawDocKind kind;
std::string data; // Doc data or file name
struct stat st; // Only used if RDK_FILENAME
};
/**
@@ -73,11 +74,16 @@ public:
*/
virtual bool makesig(RclConfig* cnf, const Rcl::Doc& idoc,
std::string& sig) = 0;
enum Reason{FetchOk, FetchNotExist, FetchNoPerm, FetchOther};
virtual Reason testAccess(RclConfig* cnf, const Rcl::Doc& idoc) {
return FetchOther;
}
virtual ~DocFetcher() {}
};
/** Return an appropriate fetcher object given the backend string
* identifier inside idoc*/
DocFetcher *docFetcherMake(RclConfig *config, const Rcl::Doc& idoc);
std::unique_ptr<DocFetcher> docFetcherMake(RclConfig *config,
const Rcl::Doc& idoc);
#endif /* _FETCHER_H_INCLUDED_ */
+28 -13
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2012 J.F.Dockes
/* Copyright (C) 2012-2019 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -28,31 +28,32 @@
using std::string;
static bool urltopath(RclConfig* cnf,
const Rcl::Doc& idoc, string& fn, struct stat& st)
static DocFetcher::Reason urltopath(RclConfig* cnf, const Rcl::Doc& idoc,
string& fn, struct stat& st)
{
// The url has to be like file://
fn = fileurltolocalpath(idoc.url);
if (fn.empty()) {
LOGERR("FSDocFetcher::fetch/sig: non fs url: [" << (idoc.url) << "]\n" );
return false;
LOGERR("FSDocFetcher::fetch/sig: non fs url: [" << idoc.url << "]\n");
return DocFetcher::FetchOther;
}
cnf->setKeyDir(path_getfather(fn));
bool follow = false;
cnf->getConfParam("followLinks", &follow);
if (path_fileprops(fn, &st, follow) < 0) {
LOGERR("FSDocFetcher::fetch: stat errno " << (errno) << " for [" << (fn) << "]\n" );
return false;
LOGERR("FSDocFetcher::fetch: stat errno " << errno << " for [" << fn
<< "]\n");
return DocFetcher::FetchNotExist;
}
return true;
return DocFetcher::FetchOk;
}
bool FSDocFetcher::fetch(RclConfig* cnf, const Rcl::Doc& idoc, RawDoc& out)
{
string fn;
if (!urltopath(cnf, idoc, fn, out.st))
return false;
if (urltopath(cnf, idoc, fn, out.st) != DocFetcher::FetchOk)
return false;
out.kind = RawDoc::RDK_FILENAME;
out.data = fn;
return true;
@@ -62,10 +63,24 @@ bool FSDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
{
string fn;
struct stat st;
if (!urltopath(cnf, idoc, fn, st))
return false;
if (urltopath(cnf, idoc, fn, st) != DocFetcher::FetchOk)
return false;
FsIndexer::makesig(&st, sig);
return true;
}
DocFetcher::Reason FSDocFetcher::testAccess(RclConfig* cnf, const Rcl::Doc& idoc)
{
string fn;
struct stat st;
DocFetcher::Reason reason = urltopath(cnf, idoc, fn, st);
if (reason != DocFetcher::FetchOk) {
return reason;
}
if (!path_readable(fn)) {
return DocFetcher::FetchNoPerm;
}
// We have no way to know if the file is fully readable without
// trying (local Windows locks), which would take too much time.
return DocFetcher::FetchOther;
}
+1
View File
@@ -28,6 +28,7 @@ class FSDocFetcher : public DocFetcher{
/** Calls stat to retrieve file signature data */
virtual bool makesig(RclConfig* cnf,const Rcl::Doc& idoc, std::string& sig);
virtual DocFetcher::Reason testAccess(RclConfig* cnf, const Rcl::Doc& idoc);
virtual ~FSDocFetcher() {}
};