---
src/db/update/ExcludeList.cxx | 18 +++++-------------
src/db/update/ExcludeList.hxx | 39 +++++++++++++++++++++++++++++++--------
2 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/src/db/update/ExcludeList.cxx b/src/db/update/ExcludeList.cxx
index 631d452..832828b 100644
--- a/src/db/update/ExcludeList.cxx
+++ b/src/db/update/ExcludeList.cxx
@@ -35,26 +35,27 @@
#include <string.h>
#include <errno.h>
-#ifdef HAVE_GLIB
-
gcc_pure
static bool
IsFileNotFound(const Error &error)
{
+#ifdef HAVE_GLIB
#ifdef WIN32
return error.IsDomain(win32_domain) &&
error.GetCode() == ERROR_FILE_NOT_FOUND;
#else
return error.IsDomain(errno_domain) && error.GetCode() == ENOENT;
#endif
+#else
+ (void) error;
+ return true;
+#endif
}
-#endif
bool
ExcludeList::LoadFile(Path path_fs)
{
-#ifdef HAVE_GLIB
Error error;
TextFile file(path_fs, error);
if (file.HasFailed()) {
@@ -73,10 +74,6 @@ ExcludeList::LoadFile(Path path_fs)
if (*p != 0)
patterns.emplace_front(p);
}
-#else
- // TODO: implement
- (void)path_fs;
-#endif
return true;
}
@@ -88,14 +85,9 @@ ExcludeList::Check(Path name_fs) const
/* XXX include full path name in check */
-#ifdef HAVE_GLIB
for (const auto &i : patterns)
if (i.Check(NarrowPath(name_fs).c_str()))
return true;
-#else
- // TODO: implement
- (void)name_fs;
-#endif
return false;
}
diff --git a/src/db/update/ExcludeList.hxx b/src/db/update/ExcludeList.hxx
index ae196a7..03d45f6 100644
--- a/src/db/update/ExcludeList.hxx
+++ b/src/db/update/ExcludeList.hxx
@@ -32,6 +32,9 @@
#ifdef HAVE_GLIB
#include <glib.h>
+#else
+#include <sys/types.h>
+#include <regex.h>
#endif
class Path;
@@ -59,21 +62,41 @@ class ExcludeList {
return g_pattern_match_string(pattern, name_fs);
}
};
-
- std::forward_list<Pattern> patterns;
#else
- // TODO: implement
+ class Pattern {
+ int ret;
+ regex_t preg;
+
+ public:
+ Pattern(const char *_pattern)
+ {
+ ret = regcomp(&preg, _pattern, REG_EXTENDED|REG_NOSUB);
+ }
+
+ Pattern(Pattern &&other)
+ :ret(other.ret), preg(other.preg) {
+ other.ret = -1;
+ }
+
+ ~Pattern() {
+ if (ret == 0)
+ regfree(&preg);
+ }
+
+ gcc_pure
+ bool Check(const char *name_fs) const {
+ return ret == 0 &&
+ regexec(&preg, name_fs, 0, nullptr, 0) == 0;
+ }
+ };
#endif
+ std::forward_list<Pattern> patterns;
+
public:
gcc_pure
bool IsEmpty() const {
-#ifdef HAVE_GLIB
return patterns.empty();
-#else
- // TODO: implement
- return true;
-#endif
}
/**
--
2.1.4
_______________________________________________
mpd-devel mailing list
[email protected]
http://mailman.blarg.de/listinfo/mpd-devel