2009-10-16 18:11:43 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 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"
|
2015-03-25 17:32:17 +01:00
|
|
|
#include "fs/NarrowPath.hxx"
|
2015-02-25 16:24:40 +01:00
|
|
|
#include "fs/io/TextFile.hxx"
|
2015-12-16 11:05:33 +01:00
|
|
|
#include "system/Error.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2009-10-16 18:11:43 +02:00
|
|
|
|
2016-04-13 11:51:01 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2009-10-16 18:11:43 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
bool
|
2017-06-03 21:33:44 +02:00
|
|
|
ExcludeList::LoadFile(Path path_fs) noexcept
|
2015-12-16 11:05:33 +01:00
|
|
|
try {
|
2015-06-22 21:01:46 +02:00
|
|
|
#ifdef HAVE_CLASS_GLOB
|
2015-12-16 11:05:33 +01:00
|
|
|
TextFile file(path_fs);
|
2009-10-16 18:11:43 +02:00
|
|
|
|
2015-02-25 16:24:40 +01:00
|
|
|
char *line;
|
|
|
|
while ((line = file.ReadLine()) != 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;
|
|
|
|
|
2014-02-17 22:37:43 +01:00
|
|
|
p = Strip(line);
|
2009-10-16 18:11:43 +02:00
|
|
|
if (*p != 0)
|
2013-01-03 10:01:34 +01:00
|
|
|
patterns.emplace_front(p);
|
2009-10-16 18:11:43 +02:00
|
|
|
}
|
2014-03-01 08:16:13 +01:00
|
|
|
#else
|
2015-06-22 21:14:25 +02:00
|
|
|
/* not implemented */
|
2014-03-01 08:16:13 +01:00
|
|
|
(void)path_fs;
|
|
|
|
#endif
|
2009-10-16 18:11:43 +02:00
|
|
|
|
2013-01-03 10:01:34 +01:00
|
|
|
return true;
|
2015-12-16 11:05:33 +01:00
|
|
|
} catch (const std::system_error &e) {
|
|
|
|
if (!IsFileNotFound(e))
|
|
|
|
LogError(e);
|
|
|
|
return false;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
LogError(e);
|
|
|
|
return false;
|
2009-10-16 18:11:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-06-03 21:33:44 +02:00
|
|
|
ExcludeList::Check(Path name_fs) const noexcept
|
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 */
|
|
|
|
|
2015-06-22 21:01:46 +02:00
|
|
|
#ifdef HAVE_CLASS_GLOB
|
2015-09-29 19:39:07 +02:00
|
|
|
if (parent != nullptr) {
|
|
|
|
if (parent->Check(name_fs)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 11:51:01 +02:00
|
|
|
for (const auto &i : patterns) {
|
|
|
|
try {
|
|
|
|
if (i.Check(NarrowPath(name_fs).c_str()))
|
|
|
|
return true;
|
|
|
|
} catch (const std::runtime_error &) {
|
|
|
|
}
|
|
|
|
}
|
2014-03-01 08:16:13 +01:00
|
|
|
#else
|
2015-06-22 21:14:25 +02:00
|
|
|
/* not implemented */
|
2014-03-01 08:16:13 +01:00
|
|
|
(void)name_fs;
|
|
|
|
#endif
|
2009-10-16 18:11:43 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|