2014-02-07 23:25:47 +01:00
|
|
|
/*
|
2016-02-26 17:54:05 +01:00
|
|
|
* Copyright 2003-2016 The Music Player Daemon Project
|
2014-02-07 23:25:47 +01: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "CheckFile.hxx"
|
|
|
|
#include "Log.hxx"
|
|
|
|
#include "config/ConfigError.hxx"
|
2015-02-28 20:42:50 +01:00
|
|
|
#include "FileInfo.hxx"
|
2014-02-07 23:25:47 +01:00
|
|
|
#include "Path.hxx"
|
|
|
|
#include "AllocatedPath.hxx"
|
|
|
|
#include "DirectoryReader.hxx"
|
2015-12-29 12:41:45 +01:00
|
|
|
#include "system/Error.hxx"
|
2014-02-07 23:25:47 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
CheckDirectoryReadable(Path path_fs)
|
2016-11-10 11:36:04 +01:00
|
|
|
try {
|
|
|
|
const auto path_utf8 = path_fs.ToUTF8();
|
2014-02-07 23:25:47 +01:00
|
|
|
|
2016-11-10 11:36:04 +01:00
|
|
|
const FileInfo fi(path_fs);
|
2015-02-28 20:42:50 +01:00
|
|
|
if (!fi.IsDirectory()) {
|
2014-02-07 23:25:47 +01:00
|
|
|
FormatError(config_domain,
|
2015-02-28 21:30:51 +01:00
|
|
|
"Not a directory: %s", path_utf8.c_str());
|
2014-02-07 23:25:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2016-11-10 11:36:04 +01:00
|
|
|
try {
|
|
|
|
const auto x = AllocatedPath::Build(path_fs,
|
|
|
|
PathTraitsFS::CURRENT_DIRECTORY);
|
|
|
|
const FileInfo fi2(x);
|
|
|
|
} catch (const std::system_error &e) {
|
|
|
|
if (e.code().category() == std::system_category() &&
|
|
|
|
e.code().value() == EACCES)
|
|
|
|
FormatError(config_domain,
|
|
|
|
"No permission to traverse (\"execute\") directory: %s",
|
|
|
|
path_utf8.c_str());
|
2015-02-28 21:30:51 +01:00
|
|
|
}
|
2014-02-07 23:25:47 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-29 12:41:45 +01:00
|
|
|
try {
|
|
|
|
const DirectoryReader reader(path_fs);
|
|
|
|
} catch (const std::system_error &e) {
|
|
|
|
if (IsAccessDenied(e))
|
|
|
|
FormatError(config_domain,
|
|
|
|
"No permission to read directory: %s",
|
|
|
|
path_fs.ToUTF8().c_str());
|
2015-02-28 21:30:51 +01:00
|
|
|
}
|
2016-11-10 11:36:04 +01:00
|
|
|
} catch (const std::runtime_error &e) {
|
|
|
|
LogError(e);
|
2014-02-07 23:25:47 +01:00
|
|
|
}
|