2014-02-07 23:25:47 +01:00
|
|
|
/*
|
2022-07-14 17:58:12 +02:00
|
|
|
* Copyright 2003-2022 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 "CheckFile.hxx"
|
|
|
|
#include "Log.hxx"
|
2021-06-24 20:22:48 +02:00
|
|
|
#include "lib/fmt/PathFormatter.hxx"
|
2018-07-16 19:50:07 +02:00
|
|
|
#include "config/Domain.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
|
|
|
|
|
|
|
void
|
|
|
|
CheckDirectoryReadable(Path path_fs)
|
2016-11-10 11:36:04 +01:00
|
|
|
try {
|
|
|
|
const FileInfo fi(path_fs);
|
2015-02-28 20:42:50 +01:00
|
|
|
if (!fi.IsDirectory()) {
|
2021-06-24 20:22:48 +02:00
|
|
|
FmtError(config_domain, "Not a directory: {}", path_fs);
|
2014-02-07 23:25:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifndef _WIN32
|
2016-11-10 11:36:04 +01:00
|
|
|
try {
|
2018-07-17 17:01:02 +02:00
|
|
|
const auto x = path_fs / Path::FromFS(PathTraitsFS::CURRENT_DIRECTORY);
|
2016-11-10 11:36:04 +01:00
|
|
|
const FileInfo fi2(x);
|
|
|
|
} catch (const std::system_error &e) {
|
2016-12-04 19:56:19 +01:00
|
|
|
if (IsAccessDenied(e))
|
2021-06-24 20:22:48 +02:00
|
|
|
FmtError(config_domain,
|
|
|
|
"No permission to traverse (\"execute\") directory: {}",
|
|
|
|
path_fs);
|
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))
|
2021-06-24 20:22:48 +02:00
|
|
|
FmtError(config_domain,
|
|
|
|
"No permission to read directory: {}",
|
|
|
|
path_fs);
|
2015-02-28 21:30:51 +01:00
|
|
|
}
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
|
|
|
LogError(std::current_exception());
|
2014-02-07 23:25:47 +01:00
|
|
|
}
|