Add and interface a script to move the files generated by the WebExtensions new browser extension into the web input queue
This commit is contained in:
@@ -125,6 +125,7 @@ bool ConfIndexer::index(bool resetbefore, ixType typestorun, int flags)
|
||||
}
|
||||
#ifndef DISABLE_WEB_INDEXER
|
||||
if (m_doweb && (typestorun & IxTWebQueue)) {
|
||||
runWebFilesMoverScript(m_config);
|
||||
deleteZ(m_webindexer);
|
||||
m_webindexer = new BeagleQueueIndexer(m_config, &m_db, m_updater);
|
||||
if (!m_webindexer || !m_webindexer->index()) {
|
||||
|
||||
+14
-6
@@ -464,15 +464,22 @@ bool startMonitor(RclConfig *conf, int opts)
|
||||
bool timedout;
|
||||
time_t lastauxtime = time(0);
|
||||
time_t lastixtime = lastauxtime;
|
||||
time_t lastmovetime = 0;
|
||||
bool didsomething = false;
|
||||
list<string> modified;
|
||||
list<string> deleted;
|
||||
|
||||
;
|
||||
|
||||
// Set a relatively short timeout for better monitoring of exit requests
|
||||
while (true) {
|
||||
time_t now = time(0);
|
||||
if (now - lastmovetime > ixinterval) {
|
||||
lastmovetime = now;
|
||||
runWebFilesMoverScript(conf);
|
||||
}
|
||||
|
||||
{
|
||||
// Wait for event or timeout.
|
||||
// Set a relatively short timeout for better monitoring of
|
||||
// exit requests.
|
||||
std::unique_lock<std::mutex> lock = rclEQ.wait(2, &timedout);
|
||||
|
||||
// x11IsAlive() can't be called from ok() because both
|
||||
@@ -525,9 +532,9 @@ bool startMonitor(RclConfig *conf, int opts)
|
||||
}
|
||||
}
|
||||
|
||||
now = time(0);
|
||||
// Process. We don't do this every time but let the lists accumulate
|
||||
// a little, this saves processing. Start at once if list is big.
|
||||
time_t now = time(0);
|
||||
if (expeditedIndexingRequested(conf) ||
|
||||
(now - lastixtime > ixinterval) ||
|
||||
(deleted.size() + modified.size() > 20)) {
|
||||
@@ -553,8 +560,9 @@ bool startMonitor(RclConfig *conf, int opts)
|
||||
}
|
||||
|
||||
// Recreate the auxiliary dbs every hour at most.
|
||||
if (didsomething && time(0) - lastauxtime > auxinterval) {
|
||||
lastauxtime = time(0);
|
||||
now = time(0);
|
||||
if (didsomething && now - lastauxtime > auxinterval) {
|
||||
lastauxtime = now;
|
||||
didsomething = false;
|
||||
if (!createAuxDbs(conf)) {
|
||||
// We used to bail out on error here. Not anymore,
|
||||
|
||||
@@ -337,6 +337,48 @@ static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool runWebFilesMoverScript(RclConfig *config)
|
||||
{
|
||||
static string downloadsdir;
|
||||
if (downloadsdir.empty()) {
|
||||
if (!config->getConfParam("downloadsdir", downloadsdir)) {
|
||||
downloadsdir = path_tildexpand("~/Downloads");
|
||||
}
|
||||
}
|
||||
static string cmdpath;
|
||||
if (cmdpath.empty()) {
|
||||
cmdpath = config->findFilter("recoll-we-move-files.py");
|
||||
if (cmdpath.empty()) {
|
||||
LOGERR("runWFMoverScript: recoll-we-move-files.py not found\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Arrange to not actually run the script if the directory did not change */
|
||||
static time_t dirmtime;
|
||||
time_t ndirmtime = 0;
|
||||
struct stat st;
|
||||
if (::stat(downloadsdir.c_str(), &st) == 0) {
|
||||
ndirmtime = st.st_mtime;
|
||||
}
|
||||
/* If stat fails, presumably Downloads does not exist or is not
|
||||
accessible, dirmtime and mdirmtime stay at 0, and we never
|
||||
execute the script, which is the right thing. */
|
||||
if (dirmtime != ndirmtime) {
|
||||
/* The script is going to change the directory, so updating
|
||||
dirmtime before it runs means that we are going to execute
|
||||
it one time too many (it will run without doing anything),
|
||||
but we can't set the mtime to after the run in case files
|
||||
are created during the run. */
|
||||
dirmtime = ndirmtime;
|
||||
ExecCmd cmd;
|
||||
int status = cmd.doexec(cmdpath, {});
|
||||
return status == 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static const char *thisprog;
|
||||
|
||||
static const char usage [] =
|
||||
|
||||
@@ -26,6 +26,16 @@ extern bool indexfiles(RclConfig *config, std::list<std::string> &filenames);
|
||||
extern bool purgefiles(RclConfig *config, std::list<std::string> &filenames);
|
||||
extern bool createAuxDbs(RclConfig *config);
|
||||
|
||||
/**
|
||||
* Helper method for executing the recoll-we (new WebExtensions plugin) helper
|
||||
* script. This moves files from the browser download directory (only
|
||||
* place where the browser accepts to create them), to the web queue
|
||||
* dir). This keeps the c++ code compatible with old and new addon.
|
||||
* The script is executed before a batch pass, or from time to time in
|
||||
* the monitor, if web processing is enabled.
|
||||
*/
|
||||
extern bool runWebFilesMoverScript(RclConfig *);
|
||||
|
||||
extern int stopindexing;
|
||||
|
||||
// Try to explain what went wrong...
|
||||
|
||||
Reference in New Issue
Block a user