2013-09-27 22:31:24 +02:00
|
|
|
|
2009-10-16 18:11:43 +02:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-10-16 18:11:43 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The .mpdignore backend code.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-03 09:51:35 +01:00
|
|
|
#include "ExcludeList.hxx"
|
2013-01-21 19:14:37 +01:00
|
|
|
#include "fs/Path.hxx"
|
2013-02-02 15:20:24 +01:00
|
|
|
#include "fs/FileSystem.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "util/Domain.hxx"
|
|
|
|
#include "Log.hxx"
|
2009-10-16 18:11:43 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2013-09-27 22:31:24 +02:00
|
|
|
static constexpr Domain exclude_list_domain("exclude_list");
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
bool
|
2013-10-17 21:59:35 +02:00
|
|
|
ExcludeList::LoadFile(Path path_fs)
|
2009-10-16 18:11:43 +02:00
|
|
|
{
|
2013-02-02 15:20:24 +01:00
|
|
|
FILE *file = FOpen(path_fs, FOpenMode::ReadText);
|
2013-10-19 18:19:03 +02:00
|
|
|
if (file == nullptr) {
|
2013-09-27 22:31:24 +02:00
|
|
|
const int e = errno;
|
|
|
|
if (e != ENOENT) {
|
2013-01-23 19:48:14 +01:00
|
|
|
const auto path_utf8 = path_fs.ToUTF8();
|
2013-09-27 22:31:24 +02:00
|
|
|
FormatErrno(exclude_list_domain,
|
|
|
|
"Failed to open %s",
|
|
|
|
path_utf8.c_str());
|
2009-10-16 18:11:43 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
return false;
|
2009-10-16 18:11:43 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 10:01:48 +01:00
|
|
|
char line[1024];
|
2013-10-19 18:19:03 +02:00
|
|
|
while (fgets(line, sizeof(line), file) != nullptr) {
|
2009-10-16 18:11:43 +02:00
|
|
|
char *p = strchr(line, '#');
|
2013-10-19 18:19:03 +02:00
|
|
|
if (p != nullptr)
|
2009-10-16 18:11:43 +02:00
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
p = g_strstrip(line);
|
|
|
|
if (*p != 0)
|
2013-01-03 10:01:34 +01:00
|
|
|
patterns.emplace_front(p);
|
2009-10-16 18:11:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
return true;
|
2009-10-16 18:11:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-10-17 21:59:35 +02:00
|
|
|
ExcludeList::Check(Path name_fs) const
|
2009-10-16 18:11:43 +02:00
|
|
|
{
|
2013-05-05 10:58:07 +02:00
|
|
|
assert(!name_fs.IsNull());
|
2009-10-16 18:11:43 +02:00
|
|
|
|
|
|
|
/* XXX include full path name in check */
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
for (const auto &i : patterns)
|
2013-05-05 10:58:07 +02:00
|
|
|
if (i.Check(name_fs.c_str()))
|
2009-10-16 18:11:43 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|