remove struct stat from interfaces

This commit is contained in:
Jean-Francois Dockes
2020-03-31 11:17:07 +02:00
parent b5086139aa
commit 34d23589a2
23 changed files with 233 additions and 223 deletions
+2 -2
View File
@@ -17,11 +17,11 @@
#ifndef _FETCHER_H_INCLUDED_
#define _FETCHER_H_INCLUDED_
#include "safesysstat.h"
#include <string>
#include <memory>
#include "rcldoc.h"
#include "pathut.h"
class RclConfig;
@@ -51,7 +51,7 @@ public:
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
struct PathStat st; // Only used if RDK_FILENAME
};
/**
+3 -4
View File
@@ -17,7 +17,6 @@
#include "autoconfig.h"
#include <errno.h>
#include "safesysstat.h"
#include "log.h"
#include "cstr.h"
@@ -29,7 +28,7 @@
using std::string;
static DocFetcher::Reason urltopath(RclConfig* cnf, const Rcl::Doc& idoc,
string& fn, struct stat& st)
string& fn, struct PathStat& st)
{
// The url has to be like file://
fn = fileurltolocalpath(idoc.url);
@@ -62,7 +61,7 @@ bool FSDocFetcher::fetch(RclConfig* cnf, const Rcl::Doc& idoc, RawDoc& out)
bool FSDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
{
string fn;
struct stat st;
struct PathStat st;
if (urltopath(cnf, idoc, fn, st) != DocFetcher::FetchOk)
return false;
FsIndexer::makesig(&st, sig);
@@ -72,7 +71,7 @@ bool FSDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
DocFetcher::Reason FSDocFetcher::testAccess(RclConfig* cnf, const Rcl::Doc& idoc)
{
string fn;
struct stat st;
struct PathStat st;
DocFetcher::Reason reason = urltopath(cnf, idoc, fn, st);
if (reason != DocFetcher::FetchOk) {
return reason;
+15 -15
View File
@@ -21,7 +21,6 @@
#include <stdio.h>
#include <errno.h>
#include <cstring>
#include "safesysstat.h"
#include <iostream>
#include <list>
@@ -69,14 +68,14 @@ extern void *FsIndexerDbUpdWorker(void*);
class InternfileTask {
public:
// Take some care to avoid sharing string data (if string impl is cow)
InternfileTask(const std::string &f, const struct stat *i_stp,
InternfileTask(const std::string &f, const struct PathStat *i_stp,
map<string,string> lfields)
: fn(f.begin(), f.end()), statbuf(*i_stp)
{
map_ss_cp_noshr(lfields, &localfields);
}
string fn;
struct stat statbuf;
struct PathStat statbuf;
map<string,string> localfields;
};
extern void *FsIndexerInternfileWorker(void*);
@@ -369,7 +368,7 @@ bool FsIndexer::indexFiles(list<string>& files, int flags)
continue;
}
struct stat stb;
struct PathStat stb;
int ststat = path_fileprops(*it, &stb, follow);
if (ststat != 0) {
LOGERR("FsIndexer::indexFiles: (l)stat " << *it << ": " <<
@@ -378,7 +377,8 @@ bool FsIndexer::indexFiles(list<string>& files, int flags)
continue;
}
if (!(flags & ConfIndexer::IxFIgnoreSkip) &&
(S_ISREG(stb.st_mode) || S_ISLNK(stb.st_mode))) {
(stb.pst_type == PathStat::PST_REGULAR ||
stb.pst_type == PathStat::PST_SYMLINK)) {
if (!walker.inOnlyNames(path_getsimple(*it))) {
it++;
continue;
@@ -499,10 +499,10 @@ void FsIndexer::setlocalfields(const map<string, string>& fields, Rcl::Doc& doc)
}
}
void FsIndexer::makesig(const struct stat *stp, string& out)
void FsIndexer::makesig(const struct PathStat *stp, string& out)
{
out = lltodecstr(stp->st_size) +
lltodecstr(o_uptodate_test_use_mtime ? stp->st_mtime : stp->st_ctime);
out = lltodecstr(stp->pst_size) +
lltodecstr(o_uptodate_test_use_mtime ? stp->pst_mtime : stp->pst_ctime);
}
#ifdef IDX_THREADS
@@ -572,7 +572,7 @@ void *FsIndexerInternfileWorker(void * fsp)
/// the actual indexing work. The Rcl::Doc created by internfile()
/// mostly contains pretty raw utf8 data.
FsTreeWalker::Status
FsIndexer::processone(const std::string &fn, const struct stat *stp,
FsIndexer::processone(const std::string &fn, const struct PathStat *stp,
FsTreeWalker::CbFlag flg)
{
if (m_updater) {
@@ -633,7 +633,7 @@ bool FsIndexer::launchAddOrUpdate(const string& udi, const string& parent_udi,
FsTreeWalker::Status
FsIndexer::processonefile(RclConfig *config,
const std::string &fn, const struct stat *stp,
const std::string &fn, const struct PathStat *stp,
const map<string, string>& localfields)
{
////////////////////
@@ -671,7 +671,7 @@ FsIndexer::processonefile(RclConfig *config,
// miss the data update. We would have to store both the mtime and
// the ctime to avoid this
bool xattronly = m_detectxattronly && !m_db->inFullReset() &&
existingDoc && needupdate && (stp->st_mtime < stp->st_ctime);
existingDoc && needupdate && (stp->pst_mtime < stp->pst_ctime);
LOGDEB("processone: needupdate " << needupdate << " noretry " <<
m_noretryfailed << " existing " << existingDoc << " oldsig [" <<
@@ -708,7 +708,7 @@ FsIndexer::processonefile(RclConfig *config,
}
LOGDEB0("processone: processing: [" <<
displayableBytes(stp->st_size) << "] " << fn << "\n");
displayableBytes(stp->pst_size) << "] " << fn << "\n");
// Note that we used to do the full path here, but I ended up
// believing that it made more sense to use only the file name
@@ -720,7 +720,7 @@ FsIndexer::processonefile(RclConfig *config,
Rcl::Doc doc;
char ascdate[30];
sprintf(ascdate, "%ld", long(stp->st_mtime));
sprintf(ascdate, "%ld", long(stp->pst_mtime));
bool hadNullIpath = false;
string mimetype;
@@ -789,7 +789,7 @@ FsIndexer::processonefile(RclConfig *config,
// Set container file name for all docs, top or subdoc
doc.meta[Rcl::Doc::keytcfn] = utf8fn;
doc.pcbytes = lltodecstr(stp->st_size);
doc.pcbytes = lltodecstr(stp->pst_size);
// Document signature for up to date checks. All subdocs inherit the
// file's.
doc.sig = sig;
@@ -880,7 +880,7 @@ FsIndexer::processonefile(RclConfig *config,
fileDoc.url = path_pathtofileurl(fn);
if (m_havelocalfields)
setlocalfields(localfields, fileDoc);
fileDoc.pcbytes = lltodecstr(stp->st_size);
fileDoc.pcbytes = lltodecstr(stp->pst_size);
}
fileDoc.sig = sig;
+5 -4
View File
@@ -28,7 +28,7 @@
class DbIxStatusUpdater;
class FIMissingStore;
struct stat;
struct PathStat;
class DbUpdTask;
class InternfileTask;
@@ -75,10 +75,10 @@ public:
/** Tree walker callback method */
FsTreeWalker::Status
processone(const string &fn, const struct stat *, FsTreeWalker::CbFlag);
processone(const string &fn, const struct PathStat *, FsTreeWalker::CbFlag);
/** Make signature for file up to date checks */
static void makesig(const struct stat *stp, string& out);
static void makesig(const struct PathStat *stp, string& out);
private:
@@ -160,7 +160,8 @@ private:
string getDbDir() {return m_config->getDbDir();}
FsTreeWalker::Status
processonefile(RclConfig *config, const string &fn,
const struct stat *, const map<string,string>& localfields);
const struct PathStat *,
const map<string,string>& localfields);
};
#endif /* _fsindexer_h_included_ */
+2 -3
View File
@@ -33,7 +33,6 @@
#include "pathut.h"
#include "idxstatus.h"
#include "execmd.h"
#include "safesysstat.h"
#ifdef RCL_USE_ASPELL
#include "rclaspell.h"
@@ -86,9 +85,9 @@ bool runWebFilesMoverScript(RclConfig *config)
/* Arrange to not actually run the script if the directory did not change */
static time_t dirmtime;
time_t ndirmtime = 0;
struct stat st;
struct PathStat st;
if (path_fileprops(downloadsdir.c_str(), &st) == 0) {
ndirmtime = st.st_mtime;
ndirmtime = st.pst_mtime;
}
/* If stat fails, presumably Downloads does not exist or is not
accessible, dirmtime and mdirmtime stay at 0, and we never
+5 -54
View File
@@ -15,11 +15,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef TEST_MIMETYPE
#include "autoconfig.h"
#include "safesysstat.h"
#include <ctype.h>
#include <string>
#include <list>
@@ -139,7 +136,7 @@ static string mimetypefromdata(RclConfig *cfg, 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.
string mimetype(const string &fn, const struct stat *stp,
string mimetype(const string &fn, const struct PathStat *stp,
RclConfig *cfg, bool usfc)
{
// Use stat data if available to check for non regular files
@@ -149,14 +146,14 @@ string mimetype(const string &fn, const struct stat *stp,
// comes from bsd. Thos may surprise a user trying to use a
// 'mime:' filter with the query language, but it's not work
// changing (would force a reindex).
if (S_ISDIR(stp->st_mode))
if (stp->pst_type == PathStat::PST_DIR)
return "inode/directory";
if (S_ISLNK(stp->st_mode))
if (stp->pst_type == PathStat::PST_SYMLINK)
return "inode/symlink";
if (!S_ISREG(stp->st_mode))
if (stp->pst_type != PathStat::PST_REGULAR)
return "inode/x-fsspecial";
// Empty files are just this: avoid further errors with actual filters.
if (stp->st_size == 0)
if (stp->pst_size == 0)
return "inode/x-empty";
}
@@ -203,49 +200,3 @@ string mimetype(const string &fn, const struct stat *stp,
return mtype;
}
#else // TEST->
#include <stdio.h>
#include "safesysstat.h"
#include <cstdlib>
#include <iostream>
#include "log.h"
#include "rclconfig.h"
#include "rclinit.h"
#include "mimetype.h"
using namespace std;
int main(int argc, const char **argv)
{
string reason;
RclConfig *config = recollinit(0, 0, 0, reason);
if (config == 0 || !config->ok()) {
string str = "Configuration problem: ";
str += reason;
fprintf(stderr, "%s\n", str.c_str());
exit(1);
}
while (--argc > 0) {
string filename = *++argv;
struct stat st;
if (lstat(filename.c_str(), &st)) {
fprintf(stderr, "Can't stat %s\n", filename.c_str());
continue;
}
cout << filename << " -> " <<
mimetype(filename, &st, config, true) << endl;
}
return 0;
}
#endif // TEST
+2 -2
View File
@@ -17,10 +17,10 @@
#ifndef _MIMETYPE_H_INCLUDED_
#define _MIMETYPE_H_INCLUDED_
#include "safesysstat.h"
#include <string>
class RclConfig;
struct PathStat;
/**
* Try to determine a mime type for file.
@@ -32,7 +32,7 @@ class RclConfig;
* @param cfg recoll config
* @param usfc Use system's 'file' command as last resort (or not)
*/
std::string mimetype(const std::string &filename, const struct stat *stp,
std::string mimetype(const std::string &filename, const struct PathStat *stp,
RclConfig *cfg, bool usfc);
+2 -8
View File
@@ -21,7 +21,6 @@
#include <errno.h>
#include <cstdio>
#include <cstring>
#include "safesysstat.h"
#include "safeunistd.h"
#include "log.h"
@@ -74,7 +73,7 @@ public:
virtual ~WalkCB() {}
virtual FsTreeWalker::Status
processone(const string &fn, const struct stat *st,
processone(const string &fn, const struct PathStat *st,
FsTreeWalker::CbFlag flg) {
MONDEB("rclMonRcvRun: processone " << fn << " m_mon " << m_mon <<
" m_mon->ok " << (m_mon ? m_mon->ok() : false) << std::endl);
@@ -182,12 +181,7 @@ void *rclMonRcvRun(void *q)
}
// We have to special-case regular files which are part of the topdirs
// list because we the tree walker only adds watches for directories
struct stat st;
if (path_fileprops(*it, &st, follow) != 0) {
LOGERR("rclMonRcvRun: stat failed for " << *it << "\n");
continue;
}
if (S_ISDIR(st.st_mode)) {
if (path_isdir(*it, follow)) {
LOGDEB("rclMonRcvRun: walking " << *it << "\n");
if (walker.walk(*it, walkcb) != FsTreeWalker::FtwOk) {
LOGERR("rclMonRcvRun: tree walk failed\n");
+2 -3
View File
@@ -26,7 +26,6 @@
#else
#include <direct.h>
#endif
#include "safesysstat.h"
#include "safefcntl.h"
#include "safeunistd.h"
@@ -264,8 +263,8 @@ public:
{
}
virtual FsTreeWalker::Status
processone(const string& fn, const struct stat *, FsTreeWalker::CbFlag flg)
{
processone(const string& fn, const struct PathStat *,
FsTreeWalker::CbFlag flg) {
if (flg== FsTreeWalker::FtwDirEnter || flg == FsTreeWalker::FtwRegular){
if (m_pats.empty()) {
cerr << "Selecting " << fn << endl;
+10 -11
View File
@@ -20,7 +20,6 @@
#include <string.h>
#include <errno.h>
#include "safesysstat.h"
#include "safeunistd.h"
#include "cstr.h"
@@ -322,13 +321,13 @@ bool WebQueueIndexer::indexFiles(list<string>& files)
LOGERR("WebQueueIndexer::indexfiles no db??\n");
return false;
}
for (list<string>::iterator it = files.begin(); it != files.end();) {
for (auto it = files.begin(); it != files.end();) {
if (it->empty()) {//??
it++; continue;
}
string father = path_getfather(*it);
if (father.compare(m_queuedir)) {
LOGDEB("WebQueueIndexer::indexfiles: skipping [" << *it << "] (nq)\n");
LOGDEB("WebQueueIndexer::indexfiles: skipping ["<<*it << "] (nq)\n");
it++; continue;
}
// Pb: we are often called with the dot file, before the
@@ -342,12 +341,12 @@ bool WebQueueIndexer::indexFiles(list<string>& files)
if (fn.empty() || fn.at(0) == '.') {
it++; continue;
}
struct stat st;
struct PathStat st;
if (path_fileprops(*it, &st) != 0) {
LOGERR("WebQueueIndexer::indexfiles: cant stat [" << *it << "]\n");
it++; continue;
}
if (!S_ISREG(st.st_mode)) {
if (st.pst_type != PathStat::PST_REGULAR) {
LOGDEB("WebQueueIndexer::indexfiles: skipping [" << *it <<
"] (nr)\n");
it++; continue;
@@ -364,14 +363,15 @@ bool WebQueueIndexer::indexFiles(list<string>& files)
FsTreeWalker::Status
WebQueueIndexer::processone(const string &path,
const struct stat *stp,
const struct PathStat *stp,
FsTreeWalker::CbFlag flg)
{
if (!m_db) //??
return FsTreeWalker::FtwError;
bool dounlink = false;
string ascdate;
if (flg != FsTreeWalker::FtwRegular)
return FsTreeWalker::FtwOk;
@@ -392,8 +392,7 @@ WebQueueIndexer::processone(const string &path,
make_udi(udipath, cstr_null, udi);
LOGDEB("WebQueueIndexer: prc1: udi [" << udi << "]\n");
char ascdate[30];
sprintf(ascdate, "%ld", long(stp->st_mtime));
ascdate = lltodecstr(stp->pst_mtime);
if (!stringlowercmp("bookmark", dotdoc.meta[Rcl::Doc::keybght])) {
// For bookmarks, we just index the doc that was built from the
@@ -401,7 +400,7 @@ WebQueueIndexer::processone(const string &path,
if (dotdoc.fmtime.empty())
dotdoc.fmtime = ascdate;
dotdoc.pcbytes = lltodecstr(stp->st_size);
dotdoc.pcbytes = lltodecstr(stp->pst_size);
// Document signature for up to date checks: none.
dotdoc.sig.clear();
@@ -439,7 +438,7 @@ WebQueueIndexer::processone(const string &path,
doc.fmtime = ascdate;
dotdoc.fmtime = doc.fmtime;
doc.pcbytes = lltodecstr(stp->st_size);
doc.pcbytes = lltodecstr(stp->pst_size);
// Document signature for up to date checks: none.
doc.sig.clear();
doc.url = dotdoc.url;
+6 -6
View File
@@ -50,7 +50,7 @@ public:
/** Called when we fstreewalk the queue dir */
FsTreeWalker::Status
processone(const string &, const struct stat *, FsTreeWalker::CbFlag);
processone(const std::string &, const struct PathStat *, FsTreeWalker::CbFlag);
/** Index a list of files. No db cleaning or stemdb updating.
* Used by the real time monitor */
@@ -62,18 +62,18 @@ public:
/** Called when indexing data from the cache, and from internfile for
* search result preview */
bool getFromCache(const string& udi, Rcl::Doc &doc, string& data,
string *hittype = 0);
bool getFromCache(const std::string& udi, Rcl::Doc &doc, std::string& data,
std::string *hittype = 0);
private:
RclConfig *m_config;
Rcl::Db *m_db;
WebStore *m_cache;
string m_queuedir;
std::string m_queuedir;
DbIxStatusUpdater *m_updater;
bool m_nocacheindex;
bool indexFromCache(const string& udi);
void updstatus(const string& udi);
bool indexFromCache(const std::string& udi);
void updstatus(const std::string& udi);
};
#endif /* _webqueue_h_included_ */