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-17 00:43:27 +01:00
|
|
|
#include "Path.hxx"
|
2009-10-16 18:11:43 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
bool
|
|
|
|
ExcludeList::LoadFile(const char *path_fs)
|
2009-10-16 18:11:43 +02:00
|
|
|
{
|
|
|
|
assert(path_fs != NULL);
|
|
|
|
|
2013-01-03 10:01:48 +01:00
|
|
|
FILE *file = fopen(path_fs, "r");
|
2009-10-16 18:11:43 +02:00
|
|
|
if (file == NULL) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
char *path_utf8 = fs_charset_to_utf8(path_fs);
|
|
|
|
g_debug("Failed to open %s: %s",
|
|
|
|
path_utf8, g_strerror(errno));
|
|
|
|
g_free(path_utf8);
|
|
|
|
}
|
|
|
|
|
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];
|
2009-10-16 18:11:43 +02:00
|
|
|
while (fgets(line, sizeof(line), file) != NULL) {
|
|
|
|
char *p = strchr(line, '#');
|
|
|
|
if (p != NULL)
|
|
|
|
*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-01-03 10:01:34 +01:00
|
|
|
ExcludeList::Check(const char *name_fs) const
|
2009-10-16 18:11:43 +02:00
|
|
|
{
|
|
|
|
assert(name_fs != NULL);
|
|
|
|
|
|
|
|
/* XXX include full path name in check */
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
for (const auto &i : patterns)
|
|
|
|
if (i.Check(name_fs))
|
2009-10-16 18:11:43 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|