|
a/src/utils/pathut.cpp |
|
b/src/utils/pathut.cpp |
|
... |
|
... |
174 |
if (!m_filename.empty())
|
174 |
if (!m_filename.empty())
|
175 |
unlink(m_filename.c_str());
|
175 |
unlink(m_filename.c_str());
|
176 |
}
|
176 |
}
|
177 |
|
177 |
|
178 |
|
178 |
|
179 |
void path_catslash(std::string &s) {
|
179 |
void path_catslash(string &s) {
|
180 |
if (s.empty() || s[s.length() - 1] != '/')
|
180 |
if (s.empty() || s[s.length() - 1] != '/')
|
181 |
s += '/';
|
181 |
s += '/';
|
182 |
}
|
182 |
}
|
183 |
|
183 |
|
184 |
std::string path_cat(const std::string &s1, const std::string &s2) {
|
184 |
string path_cat(const string &s1, const string &s2) {
|
185 |
std::string res = s1;
|
185 |
string res = s1;
|
186 |
path_catslash(res);
|
186 |
path_catslash(res);
|
187 |
res += s2;
|
187 |
res += s2;
|
188 |
return res;
|
188 |
return res;
|
189 |
}
|
189 |
}
|
190 |
|
190 |
|
|
... |
|
... |
272 |
o.replace(0, l+1, entry->pw_dir);
|
272 |
o.replace(0, l+1, entry->pw_dir);
|
273 |
}
|
273 |
}
|
274 |
return o;
|
274 |
return o;
|
275 |
}
|
275 |
}
|
276 |
|
276 |
|
277 |
extern std::string path_absolute(const std::string &is)
|
277 |
extern string path_absolute(const string &is)
|
278 |
{
|
278 |
{
|
279 |
if (is.length() == 0)
|
279 |
if (is.length() == 0)
|
280 |
return is;
|
280 |
return is;
|
281 |
string s = is;
|
281 |
string s = is;
|
282 |
if (s[0] != '/') {
|
282 |
if (s[0] != '/') {
|
|
... |
|
... |
288 |
}
|
288 |
}
|
289 |
return s;
|
289 |
return s;
|
290 |
}
|
290 |
}
|
291 |
|
291 |
|
292 |
#include <smallut.h>
|
292 |
#include <smallut.h>
|
293 |
extern std::string path_canon(const std::string &is)
|
293 |
extern string path_canon(const string &is)
|
294 |
{
|
294 |
{
|
295 |
if (is.length() == 0)
|
295 |
if (is.length() == 0)
|
296 |
return is;
|
296 |
return is;
|
297 |
string s = is;
|
297 |
string s = is;
|
298 |
if (s[0] != '/') {
|
298 |
if (s[0] != '/') {
|
|
... |
|
... |
328 |
return ret;
|
328 |
return ret;
|
329 |
}
|
329 |
}
|
330 |
|
330 |
|
331 |
#include <glob.h>
|
331 |
#include <glob.h>
|
332 |
#include <sys/stat.h>
|
332 |
#include <sys/stat.h>
|
333 |
list<std::string> path_dirglob(const std::string &dir,
|
333 |
list<string> path_dirglob(const string &dir,
|
334 |
const std::string pattern)
|
334 |
const string pattern)
|
335 |
{
|
335 |
{
|
336 |
list<string> res;
|
336 |
list<string> res;
|
337 |
glob_t mglob;
|
337 |
glob_t mglob;
|
338 |
string mypat=path_cat(dir, pattern);
|
338 |
string mypat=path_cat(dir, pattern);
|
339 |
if (glob(mypat.c_str(), 0, 0, &mglob)) {
|
339 |
if (glob(mypat.c_str(), 0, 0, &mglob)) {
|
|
... |
|
... |
354 |
if (S_ISDIR(st.st_mode))
|
354 |
if (S_ISDIR(st.st_mode))
|
355 |
return true;
|
355 |
return true;
|
356 |
return false;
|
356 |
return false;
|
357 |
}
|
357 |
}
|
358 |
|
358 |
|
359 |
std::string url_encode(const std::string url, string::size_type offs)
|
359 |
string url_encode(const string& url, string::size_type offs)
|
360 |
{
|
360 |
{
|
361 |
string out = url.substr(0, offs);
|
361 |
string out = url.substr(0, offs);
|
362 |
const char *cp = url.c_str();
|
362 |
const char *cp = url.c_str();
|
363 |
for (string::size_type i = offs; i < url.size(); i++) {
|
363 |
for (string::size_type i = offs; i < url.size(); i++) {
|
364 |
int c;
|
364 |
int c;
|
|
... |
|
... |
390 |
}
|
390 |
}
|
391 |
}
|
391 |
}
|
392 |
return out;
|
392 |
return out;
|
393 |
}
|
393 |
}
|
394 |
|
394 |
|
|
|
395 |
string url_gpath(const string& url)
|
|
|
396 |
{
|
|
|
397 |
// Remove the access schema part (or whatever it's called)
|
|
|
398 |
string::size_type colon = url.find_first_of(":");
|
|
|
399 |
if (colon == string::npos || colon == url.size() - 1)
|
|
|
400 |
return url;
|
|
|
401 |
// If there are non-alphanum chars before the ':', then there
|
|
|
402 |
// probably is no scheme. Whatever...
|
|
|
403 |
for (string::size_type i = 0; i < colon; i++) {
|
|
|
404 |
if (!isalnum(url.at(i)))
|
|
|
405 |
return url;
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
// In addition we canonize the path to remove empty host parts
|
|
|
409 |
// (for compatibility with older versions of recoll where file://
|
|
|
410 |
// was hardcoded, but the local path was used for doc
|
|
|
411 |
// identification.
|
|
|
412 |
return path_canon(url.substr(colon+1));
|
|
|
413 |
}
|
|
|
414 |
|
395 |
// Printable url: this is used to transcode from the system charset
|
415 |
// Printable url: this is used to transcode from the system charset
|
396 |
// into either utf-8 if transcoding succeeds, or url-encoded
|
416 |
// into either utf-8 if transcoding succeeds, or url-encoded
|
397 |
bool printableUrl(const string &fcharset, const string &in, string &out)
|
417 |
bool printableUrl(const string &fcharset, const string &in, string &out)
|
398 |
{
|
418 |
{
|
399 |
int ecnt = 0;
|
419 |
int ecnt = 0;
|