diff options
Diffstat (limited to 'src/db/update/ExcludeList.cxx')
-rw-r--r-- | src/db/update/ExcludeList.cxx | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/src/db/update/ExcludeList.cxx b/src/db/update/ExcludeList.cxx index cf92ac8f7..b09f349ac 100644 --- a/src/db/update/ExcludeList.cxx +++ b/src/db/update/ExcludeList.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -25,36 +25,46 @@ #include "config.h" #include "ExcludeList.hxx" #include "fs/Path.hxx" -#include "fs/FileSystem.hxx" +#include "fs/NarrowPath.hxx" +#include "fs/io/TextFile.hxx" #include "util/StringUtil.hxx" -#include "util/Domain.hxx" +#include "util/Error.hxx" #include "Log.hxx" #include <assert.h> #include <string.h> #include <errno.h> -static constexpr Domain exclude_list_domain("exclude_list"); +#ifdef HAVE_CLASS_GLOB + +gcc_pure +static bool +IsFileNotFound(const Error &error) +{ +#ifdef WIN32 + return error.IsDomain(win32_domain) && + error.GetCode() == ERROR_FILE_NOT_FOUND; +#else + return error.IsDomain(errno_domain) && error.GetCode() == ENOENT; +#endif +} + +#endif bool ExcludeList::LoadFile(Path path_fs) { -#ifdef HAVE_GLIB - FILE *file = FOpen(path_fs, FOpenMode::ReadText); - if (file == nullptr) { - const int e = errno; - if (e != ENOENT) { - const auto path_utf8 = path_fs.ToUTF8(); - FormatErrno(exclude_list_domain, - "Failed to open %s", - path_utf8.c_str()); - } - +#ifdef HAVE_CLASS_GLOB + Error error; + TextFile file(path_fs, error); + if (file.HasFailed()) { + if (!IsFileNotFound(error)) + LogError(error); return false; } - char line[1024]; - while (fgets(line, sizeof(line), file) != nullptr) { + char *line; + while ((line = file.ReadLine()) != nullptr) { char *p = strchr(line, '#'); if (p != nullptr) *p = 0; @@ -63,10 +73,8 @@ ExcludeList::LoadFile(Path path_fs) if (*p != 0) patterns.emplace_front(p); } - - fclose(file); #else - // TODO: implement + /* not implemented */ (void)path_fs; #endif @@ -80,12 +88,18 @@ ExcludeList::Check(Path name_fs) const /* XXX include full path name in check */ -#ifdef HAVE_GLIB +#ifdef HAVE_CLASS_GLOB + if (parent != nullptr) { + if (parent->Check(name_fs)) { + return true; + } + } + for (const auto &i : patterns) - if (i.Check(name_fs.c_str())) + if (i.Check(NarrowPath(name_fs).c_str())) return true; #else - // TODO: implement + /* not implemented */ (void)name_fs; #endif |