|
a/src/utils/pathut.cpp |
|
b/src/utils/pathut.cpp |
|
... |
|
... |
19 |
#include "autoconfig.h"
|
19 |
#include "autoconfig.h"
|
20 |
|
20 |
|
21 |
#include <stdio.h>
|
21 |
#include <stdio.h>
|
22 |
#include <unistd.h>
|
22 |
#include <unistd.h>
|
23 |
#include <fcntl.h>
|
23 |
#include <fcntl.h>
|
|
|
24 |
#include <dirent.h>
|
24 |
#include <sys/param.h>
|
25 |
#include <sys/param.h>
|
25 |
#include <pwd.h>
|
26 |
#include <pwd.h>
|
26 |
#include <math.h>
|
27 |
#include <math.h>
|
27 |
#include <errno.h>
|
28 |
#include <errno.h>
|
28 |
#include <sys/types.h>
|
29 |
#include <sys/types.h>
|
|
... |
|
... |
46 |
#endif
|
47 |
#endif
|
47 |
|
48 |
|
48 |
#include <cstdlib>
|
49 |
#include <cstdlib>
|
49 |
#include <cstring>
|
50 |
#include <cstring>
|
50 |
#include <iostream>
|
51 |
#include <iostream>
|
|
|
52 |
#include <sstream>
|
51 |
#include <stack>
|
53 |
#include <stack>
|
52 |
#ifndef NO_NAMESPACES
|
54 |
#include <set>
|
53 |
using std::string;
|
55 |
using namespace std;
|
54 |
using std::stack;
|
|
|
55 |
#endif /* NO_NAMESPACES */
|
|
|
56 |
|
56 |
|
57 |
#include "pathut.h"
|
57 |
#include "pathut.h"
|
58 |
#include "transcode.h"
|
58 |
#include "transcode.h"
|
59 |
#include "wipedir.h"
|
59 |
#include "wipedir.h"
|
60 |
#include "md5.h"
|
60 |
#include "md5.h"
|
|
... |
|
... |
270 |
pos = simple.rfind(suff);
|
270 |
pos = simple.rfind(suff);
|
271 |
if (pos != string::npos && pos + suff.length() == simple.length())
|
271 |
if (pos != string::npos && pos + suff.length() == simple.length())
|
272 |
return simple.substr(0, pos);
|
272 |
return simple.substr(0, pos);
|
273 |
}
|
273 |
}
|
274 |
return simple;
|
274 |
return simple;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
string path_suffix(const string& s)
|
|
|
278 |
{
|
|
|
279 |
string::size_type dotp = s.rfind('.');
|
|
|
280 |
if (dotp == string::npos)
|
|
|
281 |
return string();
|
|
|
282 |
return s.substr(dotp);
|
275 |
}
|
283 |
}
|
276 |
|
284 |
|
277 |
string path_home()
|
285 |
string path_home()
|
278 |
{
|
286 |
{
|
279 |
uid_t uid = getuid();
|
287 |
uid_t uid = getuid();
|
|
... |
|
... |
541 |
out = url_encode(in, 7);
|
549 |
out = url_encode(in, 7);
|
542 |
}
|
550 |
}
|
543 |
return true;
|
551 |
return true;
|
544 |
}
|
552 |
}
|
545 |
|
553 |
|
|
|
554 |
bool readdir(const string& dir, string& reason, set<string>& entries)
|
|
|
555 |
{
|
|
|
556 |
struct stat st;
|
|
|
557 |
int statret;
|
|
|
558 |
ostringstream msg;
|
|
|
559 |
DIR *d = 0;
|
|
|
560 |
statret = lstat(dir.c_str(), &st);
|
|
|
561 |
if (statret == -1) {
|
|
|
562 |
msg << "readdir: cant stat " << dir << " errno " << errno;
|
|
|
563 |
goto out;
|
|
|
564 |
}
|
|
|
565 |
if (!S_ISDIR(st.st_mode)) {
|
|
|
566 |
msg << "readdir: " << dir << " not a directory";
|
|
|
567 |
goto out;
|
|
|
568 |
}
|
|
|
569 |
if (access(dir.c_str(), R_OK) < 0) {
|
|
|
570 |
msg << "readdir: no read access to " << dir;
|
|
|
571 |
goto out;
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
d = opendir(dir.c_str());
|
|
|
575 |
if (d == 0) {
|
|
|
576 |
msg << "readdir: cant opendir " << dir << ", errno " << errno;
|
|
|
577 |
goto out;
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
struct dirent *ent;
|
|
|
581 |
while ((ent = readdir(d)) != 0) {
|
|
|
582 |
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
|
|
583 |
continue;
|
|
|
584 |
entries.insert(ent->d_name);
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
out:
|
|
|
588 |
if (d)
|
|
|
589 |
closedir(d);
|
|
|
590 |
reason = msg.str();
|
|
|
591 |
if (reason.empty())
|
|
|
592 |
return true;
|
|
|
593 |
return false;
|
|
|
594 |
}
|
|
|
595 |
|
546 |
// We do not want to mess with the pidfile content in the destructor:
|
596 |
// We do not want to mess with the pidfile content in the destructor:
|
547 |
// the lock might still be in use in a child process. In fact as much
|
597 |
// the lock might still be in use in a child process. In fact as much
|
548 |
// as we'd like to reset the pid inside the file when we're done, it
|
598 |
// as we'd like to reset the pid inside the file when we're done, it
|
549 |
// would be very difficult to do it right and it's probably best left
|
599 |
// would be very difficult to do it right and it's probably best left
|
550 |
// alone.
|
600 |
// alone.
|