Windows: fix path splitting for the XP field

This commit is contained in:
Jean-Francois Dockes 2015-10-14 10:53:15 +02:00
parent ba21b2f27e
commit 539ee97da7
3 changed files with 30 additions and 1 deletions

View file

@ -1307,7 +1307,7 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, Doc &doc)
// Split and index the path from the url for path-based filtering
{
string path = url_gpath(doc.url);
string path = url_gpathS(doc.url);
vector<string> vpath;
stringToTokens(path, vpath, "/");
// If vpath is not /, the last elt is the file/dir name, not a

View file

@ -805,6 +805,29 @@ string url_gpath(const string& url)
return path_canon(url.substr(colon+1));
}
string url_gpathS(const string& url)
{
#ifdef _WIN32
string u = url_gpath(url);
string nu;
if (path_hasdrive(u)) {
nu.append(1, '/');
nu.append(1, u[0]);
if (path_isdriveabs(u)) {
nu.append(u.substr(2));
} else {
// This should be an error really
nu.append(1, '/');
nu.append(u.substr(2));
}
}
return nu;
#else
return url_gpath(url);
#endif
}
string url_parentfolder(const string& url)
{
// In general, the parent is the directory above the full path

View file

@ -67,6 +67,12 @@ extern std::string url_parentfolder(const std::string& url);
/// routine, it does the right thing only in the recoll context
extern std::string url_gpath(const std::string& url);
/// Same but, in the case of a Windows local path, also turn "c:/" into
/// "/c/" This should be used only for splitting the path in rcldb, it
/// would better be local in there, but I prefer to keep all the
/// system-specific path stuff in pathut
extern std::string url_gpathS(const std::string& url);
/// Stat parameter and check if it's a directory
extern bool path_isdir(const std::string& path);