33 #include <sys/types.h>
56 if (errno == ENOENT)
return;
73 if (unlink((dirname +
"/" +
name).c_str())) {
78 if (rmdir(dirname.c_str())) {
86 has_drive(string_view path)
88 return (path.size() >= 2 && path[1] ==
':');
93 uncw_path(string_view path)
95 return (path.size() >= 4 && memcmp(path.data(),
"\\\\?\\", 4) == 0);
98 static inline bool slash(
char ch)
100 return ch ==
'/' || ch ==
'\\';
108 if (path.empty() || path[0] !=
'/') {
110 string::size_type last_slash = base.rfind(
'/');
111 if (last_slash != string::npos)
112 path.insert(0, base, 0, last_slash + 1);
117 bool drive = has_drive(path);
118 string::size_type
p = (drive ? 2 : 0);
119 bool absolute = (
p != path.size() && slash(path[
p]));
127 if (has_drive(base)) {
128 path.insert(0, base, 0, 2);
134 if (uncw_path(base)) {
135 string::size_type sl = 0;
136 if (base.size() >= 7 && memcmp(base.data() + 5,
":\\", 2) == 0) {
139 }
else if (base.size() >= 8 &&
140 memcmp(base.data() + 4,
"UNC\\", 4) == 0) {
142 sl = base.find(
'\\', 8);
143 if (sl != string::npos)
144 sl = base.find(
'\\', sl + 1);
149 for (
auto& ch : path) {
153 path.insert(0, base, 0, sl);
155 }
else if (base.size() >= 5 && slash(base[0]) && slash(base[1])) {
157 string::size_type sl = base.find_first_of(
"/\\", 2);
158 if (sl != string::npos) {
159 sl = base.find_first_of(
"/\\", sl + 1);
160 path.insert(0, base, 0, sl);
168 bool base_drive = has_drive(base);
169 if (!drive || (base_drive && (path[0] | 32) == (base[0] | 32))) {
170 string::size_type last_slash = base.find_last_of(
"/\\");
171 if (last_slash == string::npos && !drive && base_drive)
173 if (last_slash != string::npos) {
174 string::size_type b = (drive && base_drive ? 2 : 0);
175 if (uncw_path(base)) {
178 for (
auto& ch : path) {
183 path.insert(b, base, b, last_slash + 1 - b);
DatabaseError indicates some sort of database related error.
Hierarchy of classes which Xapian can throw as exceptions.
void removedir(const string &dirname)
Remove a directory, and its contents.
void resolve_relative_path(string &path, string_view base)
Resolve path relative to base.
File and path manipulation routines.
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
include <dirent.h>, with alternative implementation for windows.
<unistd.h>, but with compat.