Merged utility file versions with other packages
This commit is contained in:
parent
e6af8c6020
commit
90afc535a4
8 changed files with 79 additions and 49 deletions
|
@ -259,7 +259,7 @@ bool BeagleQueueIndexer::index()
|
|||
return false;
|
||||
LOGDEB(("BeagleQueueIndexer::processqueue: [%s]\n", m_queuedir.c_str()));
|
||||
m_config->setKeyDir(m_queuedir);
|
||||
if (!makepath(m_queuedir)) {
|
||||
if (!path_makepath(m_queuedir, 0700)) {
|
||||
LOGERR(("BeagleQueueIndexer:: can't create queuedir [%s] errno %d\n",
|
||||
m_queuedir.c_str(), errno));
|
||||
return false;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2003 J.F.Dockes
|
||||
/* Copyright (C) 2003-2016 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
|
||||
|
@ -14,15 +14,26 @@
|
|||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include "autoconfig.h"
|
||||
|
||||
#ifndef TEST_CONFTREE
|
||||
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "autoconfig.h"
|
||||
#else
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "conftree.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fnmatch.h>
|
||||
#ifdef _WIN32
|
||||
#include "safesysstat.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
@ -672,6 +683,10 @@ const
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "conftree.h"
|
||||
#include "smallut.h"
|
||||
#include "readfile.h"
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
* (useful to have central/personal config files)
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#ifdef HAVE_SPAWN_H
|
||||
#ifndef __USE_GNU
|
||||
#define __USE_GNU
|
||||
|
@ -52,6 +53,7 @@
|
|||
|
||||
#include "netcon.h"
|
||||
#include "closefrom.h"
|
||||
#include "smallut.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -59,7 +61,6 @@ extern char **environ;
|
|||
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "debuglog.h"
|
||||
#include "smallut.h"
|
||||
|
||||
#else
|
||||
// If compiling outside of recoll, make the file as standalone as reasonable.
|
||||
|
@ -74,42 +75,6 @@ extern char **environ;
|
|||
#define LOGDEB3(X)
|
||||
#define LOGDEB4(X)
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(A,B) ((A) < (B) ? (A) : (B))
|
||||
#endif
|
||||
|
||||
static void stringToTokens(const string &s, vector<string> &tokens,
|
||||
const string &delims = " \t", bool skipinit=true);
|
||||
|
||||
static void stringToTokens(const string& str, vector<string>& tokens,
|
||||
const string& delims, bool skipinit)
|
||||
{
|
||||
string::size_type startPos = 0, pos;
|
||||
|
||||
// Skip initial delims, return empty if this eats all.
|
||||
if (skipinit &&
|
||||
(startPos = str.find_first_not_of(delims, 0)) == string::npos) {
|
||||
return;
|
||||
}
|
||||
while (startPos < str.size()) {
|
||||
// Find next delimiter or end of string (end of token)
|
||||
pos = str.find_first_of(delims, startPos);
|
||||
|
||||
// Add token to the vector and adjust start
|
||||
if (pos == string::npos) {
|
||||
tokens.push_back(str.substr(startPos));
|
||||
break;
|
||||
} else if (pos == startPos) {
|
||||
// Dont' push empty tokens after first
|
||||
if (tokens.empty())
|
||||
tokens.push_back(string());
|
||||
startPos = ++pos;
|
||||
} else {
|
||||
tokens.push_back(str.substr(startPos, pos - startPos));
|
||||
startPos = ++pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // BUILDING_RECOLL
|
||||
|
||||
class ExecCmd::Internal {
|
||||
|
@ -932,6 +897,30 @@ again:
|
|||
return n;
|
||||
}
|
||||
|
||||
class GetlineWatchdog : public ExecCmdAdvise {
|
||||
public:
|
||||
GetlineWatchdog(int secs) : m_secs(secs), tstart(time(0)) {}
|
||||
void newData(int cnt) {
|
||||
if (time(0) - tstart >= m_secs) {
|
||||
throw std::runtime_error("getline timeout");
|
||||
}
|
||||
}
|
||||
int m_secs;
|
||||
time_t tstart;
|
||||
};
|
||||
|
||||
int ExecCmd::getline(string& data, int timeosecs)
|
||||
{
|
||||
GetlineWatchdog gwd(timeosecs);
|
||||
setAdvise(&gwd);
|
||||
try {
|
||||
return getline(data);
|
||||
} catch (...) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Wait for command status and clean up all resources.
|
||||
// We would like to avoid blocking here too, but there is no simple
|
||||
// way to do this. The 2 possible approaches would be to:
|
||||
|
@ -1250,6 +1239,7 @@ static char usage [] =
|
|||
" <filter> should be the path to an execm filter\n"
|
||||
" <mimetype> the type of the file parameters\n"
|
||||
"trexecmd -w cmd : do the 'which' thing\n"
|
||||
"trexecmd -l cmd test getline\n"
|
||||
;
|
||||
|
||||
static void Usage(void)
|
||||
|
@ -1266,6 +1256,7 @@ static int op_flags;
|
|||
#define OPT_r 0x20
|
||||
#define OPT_m 0x40
|
||||
#define OPT_o 0x80
|
||||
#define OPT_l 0x100
|
||||
|
||||
// Data sink for data coming out of the command. We also use it to set
|
||||
// a cancellation after a moment.
|
||||
|
@ -1347,6 +1338,7 @@ int main(int argc, char *argv[])
|
|||
case 'm': op_flags |= OPT_m; break;
|
||||
#endif
|
||||
case 'i': op_flags |= OPT_i; break;
|
||||
case 'l': op_flags |= OPT_l; break;
|
||||
case 'o': op_flags |= OPT_o; break;
|
||||
default: Usage(); break;
|
||||
}
|
||||
|
@ -1362,8 +1354,10 @@ int main(int argc, char *argv[])
|
|||
l.push_back(*argv++); argc--;
|
||||
}
|
||||
|
||||
#ifdef BUILDING_RECOLL
|
||||
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
||||
DebugLog::setfilename("stderr");
|
||||
#endif
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
if (op_flags & OPT_r) {
|
||||
|
@ -1396,6 +1390,20 @@ int main(int argc, char *argv[])
|
|||
l.erase(l.begin());
|
||||
return exercise_mhexecm(arg1, mimetype, l) ? 0 : 1;
|
||||
#endif
|
||||
} else if (op_flags & OPT_l) {
|
||||
ExecCmd mexec;
|
||||
|
||||
if (mexec.startExec(arg1, l, false, true) < 0) {
|
||||
cerr << "Startexec failed\n";
|
||||
exit(1);
|
||||
}
|
||||
string output;
|
||||
int ret = mexec.getline(output, 2);
|
||||
cerr << "Got ret " << ret << " output " << output << endl;
|
||||
cerr << "Waiting\n";
|
||||
int status = mexec.wait();
|
||||
cerr << "Got status " << status << endl;
|
||||
exit (status);
|
||||
} else {
|
||||
// Default: execute command line arguments
|
||||
ExecCmd mexec;
|
||||
|
|
|
@ -156,7 +156,13 @@ class ExecCmd {
|
|||
bool has_input, bool has_output);
|
||||
int send(const std::string& data);
|
||||
int receive(std::string& data, int cnt = -1);
|
||||
|
||||
/** Read line. Will call back periodically to check for cancellation */
|
||||
int getline(std::string& data);
|
||||
|
||||
/** Read line. Timeout after timeosecs seconds */
|
||||
int getline(std::string& data, int timeosecs);
|
||||
|
||||
int wait();
|
||||
/** Wait with WNOHANG set.
|
||||
@return true if process exited, false else.
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "pathut.h"
|
||||
#include "smallut.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -396,7 +397,6 @@ string path_absolute(const string& is)
|
|||
return s;
|
||||
}
|
||||
|
||||
#include <smallut.h>
|
||||
string path_canon(const string& is, const string* cwd)
|
||||
{
|
||||
if (is.length() == 0) {
|
||||
|
@ -456,7 +456,7 @@ string path_canon(const string& is, const string* cwd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool makepath(const string& ipath)
|
||||
bool path_makepath(const string& ipath, int mode)
|
||||
{
|
||||
string path = path_canon(ipath);
|
||||
vector<string> elems;
|
||||
|
@ -473,7 +473,7 @@ bool makepath(const string& ipath)
|
|||
// Not using path_isdir() here, because this cant grok symlinks
|
||||
// If we hit an existing file, no worry, mkdir will just fail.
|
||||
if (access(path.c_str(), 0) != 0) {
|
||||
if (mkdir(path.c_str(), 0700) != 0) {
|
||||
if (mkdir(path.c_str(), mode) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ extern bool readdir(const std::string& dir, std::string& reason,
|
|||
bool fsocc(const std::string& path, int *pc, long long *avmbs = 0);
|
||||
|
||||
/// mkdir -p
|
||||
extern bool makepath(const std::string& path);
|
||||
extern bool path_makepath(const std::string& path, int mode);
|
||||
|
||||
/// Where we create the user data subdirs
|
||||
extern std::string path_homedata();
|
||||
|
|
|
@ -15,7 +15,11 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef TEST_READFILE
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "autoconfig.h"
|
||||
#else
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include "safefcntl.h"
|
||||
|
@ -32,10 +36,6 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(A,B) ((A) < (B) ? (A) : (B))
|
||||
#endif
|
||||
|
||||
class FileToString : public FileScanDo {
|
||||
public:
|
||||
FileToString(string& data) : m_data(data) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue