Handle windows paths: mostly change tests for relative, and some other tweaks.

--HG--
branch : WINDOWSPORT
This commit is contained in:
Jean-Francois Dockes 2015-08-31 17:20:04 +02:00
parent 3aeffea387
commit 94da56aadc
12 changed files with 46 additions and 19 deletions

View File

@ -35,7 +35,7 @@ BeagleQueueCache::BeagleQueueCache(RclConfig *cnf)
ccdir = "webcache"; ccdir = "webcache";
ccdir = path_tildexpand(ccdir); ccdir = path_tildexpand(ccdir);
// If not an absolute path, compute relative to config dir // If not an absolute path, compute relative to config dir
if (ccdir.at(0) != '/') if (!path_isabsolute(ccdir))
ccdir = path_cat(cnf->getConfDir(), ccdir); ccdir = path_cat(cnf->getConfDir(), ccdir);
int maxmbs = 40; int maxmbs = 40;

View File

@ -150,7 +150,6 @@ RclConfig::RclConfig(const string *argcnf)
// Compute our data dir name, typically /usr/local/share/recoll // Compute our data dir name, typically /usr/local/share/recoll
m_datadir = path_sharedatadir(); m_datadir = path_sharedatadir();
fprintf(stderr, "RclConfig::RclConfig:: datadir: [%s]\n", m_datadir.c_str());
// We only do the automatic configuration creation thing for the default // We only do the automatic configuration creation thing for the default
// config dir, not if it was specified through -c or RECOLL_CONFDIR // config dir, not if it was specified through -c or RECOLL_CONFDIR
bool autoconfdir = false; bool autoconfdir = false;
@ -172,7 +171,6 @@ RclConfig::RclConfig(const string *argcnf)
m_confdir = path_cat(path_homedata(), path_defaultrecollconfsubdir()); m_confdir = path_cat(path_homedata(), path_defaultrecollconfsubdir());
} }
} }
fprintf(stderr, "RclConfig::RclConfig:: confdir: [%s]\n", m_confdir.c_str());
// Note: autoconfdir and isDefaultConfig() are normally the same. We just // Note: autoconfdir and isDefaultConfig() are normally the same. We just
// want to avoid the imperfect test in isDefaultConfig() if we actually know // want to avoid the imperfect test in isDefaultConfig() if we actually know

View File

@ -112,7 +112,7 @@ RclConfig *recollinit(RclInitFlags flags,
if (!logfilename.empty()) { if (!logfilename.empty()) {
logfilename = path_tildexpand(logfilename); logfilename = path_tildexpand(logfilename);
// If not an absolute path or , compute relative to config dir // If not an absolute path or , compute relative to config dir
if (logfilename.at(0) != '/' && if (!path_isabsolute(logfilename) &&
!DebugLog::DebugLog::isspecialname(logfilename.c_str())) { !DebugLog::DebugLog::isspecialname(logfilename.c_str())) {
logfilename = path_cat(config->getConfDir(), logfilename); logfilename = path_cat(config->getConfDir(), logfilename);
} }

View File

@ -258,7 +258,7 @@ static bool matchesSkipped(const vector<string>& tdl,
string canonpath = path_canon(path); string canonpath = path_canon(path);
string mpath = canonpath; string mpath = canonpath;
string topdir; string topdir;
while (mpath.length() > 1) { while (!path_isroot(mpath)) { // we assume root not in skipped paths.
for (vector<string>::const_iterator it = tdl.begin(); for (vector<string>::const_iterator it = tdl.begin();
it != tdl.end(); it++) { it != tdl.end(); it++) {
// the topdirs members are already canonized. // the topdirs members are already canonized.
@ -280,7 +280,7 @@ static bool matchesSkipped(const vector<string>& tdl,
mpath = path_getfather(mpath); mpath = path_getfather(mpath);
// getfather normally returns a path ending with /, canonic // getfather normally returns a path ending with /, canonic
// paths don't (except for '/' itself). // paths don't (except for '/' itself).
if (!mpath.empty() && mpath[mpath.size()-1] == '/') if (!path_isroot(mpath) && mpath[mpath.size()-1] == '/')
mpath.erase(mpath.size()-1); mpath.erase(mpath.size()-1);
// should not be necessary, but lets be prudent. If the // should not be necessary, but lets be prudent. If the
// path did not shorten, something is seriously amiss // path did not shorten, something is seriously amiss

View File

@ -469,7 +469,7 @@ bool RclFAM::getEvent(RclMonEvent& ev, int msecs)
MONDEB(("RclFAM::getEvent: FAMNextEvent returned\n")); MONDEB(("RclFAM::getEvent: FAMNextEvent returned\n"));
map<int,string>::const_iterator it; map<int,string>::const_iterator it;
if ((fe.filename[0] != '/') && if ((!path_isabsolute(fe.filename)) &&
(it = m_idtopath.find(fe.fr.reqnum)) != m_idtopath.end()) { (it = m_idtopath.find(fe.fr.reqnum)) != m_idtopath.end()) {
ev.m_path = path_cat(it->second, fe.filename); ev.m_path = path_cat(it->second, fe.filename);
} else { } else {

View File

@ -196,7 +196,7 @@ public:
m_dir = "mboxcache"; m_dir = "mboxcache";
m_dir = path_tildexpand(m_dir); m_dir = path_tildexpand(m_dir);
// If not an absolute path, compute relative to config dir // If not an absolute path, compute relative to config dir
if (m_dir.at(0) != '/') if (!path_isabsolute(m_dir))
m_dir = path_cat(config->getConfDir(), m_dir); m_dir = path_cat(config->getConfDir(), m_dir);
m_ok = true; m_ok = true;
} }

View File

@ -961,7 +961,7 @@ bool SearchDataClausePath::toNativeQuery(Rcl::Db &db, void *p)
vector<Xapian::Query> orqueries; vector<Xapian::Query> orqueries;
if (m_text[0] == '/') if (path_isabsolute(m_text))
orqueries.push_back(Xapian::Query(wrap_prefix(pathelt_prefix))); orqueries.push_back(Xapian::Query(wrap_prefix(pathelt_prefix)));
else else
m_text = path_tildexpand(m_text); m_text = path_tildexpand(m_text);

View File

@ -574,8 +574,8 @@ bool ConfSimple::hasNameAnywhere(const string& nm) const
int ConfTree::get(const std::string &name, string &value, const string &sk) int ConfTree::get(const std::string &name, string &value, const string &sk)
const const
{ {
if (sk.empty() || sk[0] != '/') { if (sk.empty() || !path_isabsolute(sk) ) {
// LOGDEB((stderr, "ConfTree::get: looking in global space\n")); // LOGDEB((stderr, "ConfTree::get: looking in global space for sk [%s]\n", sk.c_str()));
return ConfSimple::get(name, value, sk); return ConfSimple::get(name, value, sk);
} }
@ -588,15 +588,21 @@ int ConfTree::get(const std::string &name, string &value, const string &sk)
// Look in subkey and up its parents until root ('') // Look in subkey and up its parents until root ('')
for (;;) { for (;;) {
// LOGDEB((stderr,"ConfTree::get: looking for '%s' in '%s'\n", LOGDEB((stderr,"ConfTree::get: looking for '%s' in '%s'\n",
// name.c_str(), msk.c_str())); name.c_str(), msk.c_str()));
if (ConfSimple::get(name, value, msk)) if (ConfSimple::get(name, value, msk))
return 1; return 1;
string::size_type pos = msk.rfind("/"); string::size_type pos = msk.rfind("/");
if (pos != string::npos) { if (pos != string::npos) {
msk.replace(pos, string::npos, string()); msk.replace(pos, string::npos, string());
} else } else {
#ifdef _WIN32
if (msk.size() == 2 && isalpha(msk[0]) && msk[1] == ':')
msk.clear();
else
#endif
break; break;
}
} }
return 0; return 0;
} }

View File

@ -75,7 +75,7 @@ class DLFWImpl {
} else { } else {
fp = fopen(filename, (truncate) ? "w" : "a"); fp = fopen(filename, (truncate) ? "w" : "a");
if (fp) { if (fp) {
setvbuf(fp, 0, _IOLBF, 0); setvbuf(fp, 0, _IOLBF, BUFSIZ);
#ifdef O_APPEND #ifdef O_APPEND
{ {
int flgs = 0; int flgs = 0;
@ -83,7 +83,10 @@ class DLFWImpl {
fcntl(fileno(fp), F_SETFL, flgs|O_APPEND); fcntl(fileno(fp), F_SETFL, flgs|O_APPEND);
} }
#endif #endif
} } else {
fprintf(stderr, "Debuglog: could not open [%s] errno %d\n",
filename, errno);
}
} }
return; return;
} }

View File

@ -380,10 +380,11 @@ string path_getfather(const string &s) {
if (father.empty()) if (father.empty())
return "./"; return "./";
if (path_isroot(father))
return father;
if (father[father.length() - 1] == '/') { if (father[father.length() - 1] == '/') {
// Input ends with /. Strip it, handle special case for root // Input ends with /. Strip it, root special case was tested above
if (father.length() == 1)
return father;
father.erase(father.length()-1); father.erase(father.length()-1);
} }
@ -514,6 +515,17 @@ string path_tildexpand(const string &s)
return o; return o;
} }
bool path_isroot(const string& path)
{
if (path.size() == 1 && path[0] == '/')
return true;
#ifdef _WIN32
if (path.size == 3 && isalpha(path[0]) && path[1] == ':' && path[2] == '/')
return true;
#endif
return false;
}
bool path_isabsolute(const string &path) bool path_isabsolute(const string &path)
{ {
if (!path.empty() && (path[0] == '/' if (!path.empty() && (path[0] == '/'

View File

@ -111,6 +111,9 @@ extern const std::string& path_sharedatadir();
/// Test if path is absolute /// Test if path is absolute
extern bool path_isabsolute(const std::string& s); extern bool path_isabsolute(const std::string& s);
/// Test if path is root (x:/). root is defined by root/.. == root
extern bool path_isroot(const std::string& p);
/// Temporary file class /// Temporary file class
class TempFileInternal { class TempFileInternal {
public: public:

View File

@ -78,6 +78,11 @@ const int RDBUFSZ = 8192;
bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs, bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs,
size_t cnttoread, string *reason) size_t cnttoread, string *reason)
{ {
if (startoffs < 0) {
*reason += " file_scan: negative startoffs not allowed";
return false;
}
bool ret = false; bool ret = false;
bool noclosing = true; bool noclosing = true;
int fd = 0; int fd = 0;