2012-02-12 17:00:00 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2012-02-12 17:00:00 +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.
|
|
|
|
*/
|
|
|
|
|
2013-01-02 19:22:15 +01:00
|
|
|
#include "UpdateIO.hxx"
|
2014-02-26 09:17:41 +01:00
|
|
|
#include "db/plugins/simple/Directory.hxx"
|
2014-01-29 18:14:57 +01:00
|
|
|
#include "storage/FileInfo.hxx"
|
2014-02-05 17:03:43 +01:00
|
|
|
#include "storage/StorageInterface.hxx"
|
2014-01-29 18:14:57 +01:00
|
|
|
#include "fs/Traits.hxx"
|
2013-01-29 17:23:35 +01:00
|
|
|
#include "fs/FileSystem.hxx"
|
2014-10-01 23:38:17 +02:00
|
|
|
#include "fs/AllocatedPath.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2012-02-12 17:00:00 +01:00
|
|
|
|
2020-03-12 23:51:16 +01:00
|
|
|
#include <cerrno>
|
2012-02-12 17:00:00 +01:00
|
|
|
|
2014-01-29 18:14:57 +01:00
|
|
|
bool
|
2017-05-08 14:44:49 +02:00
|
|
|
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info) noexcept
|
2016-09-16 17:05:28 +02:00
|
|
|
try {
|
2016-10-27 08:40:40 +02:00
|
|
|
info = storage.GetInfo(uri_utf8, true);
|
|
|
|
return true;
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
|
|
|
LogError(std::current_exception());
|
2016-09-16 17:05:28 +02:00
|
|
|
return false;
|
2012-02-12 17:00:00 +01:00
|
|
|
}
|
|
|
|
|
2014-01-29 18:14:57 +01:00
|
|
|
bool
|
2017-05-08 14:44:49 +02:00
|
|
|
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info) noexcept
|
2016-09-16 17:05:28 +02:00
|
|
|
try {
|
2016-10-27 08:40:40 +02:00
|
|
|
info = reader.GetInfo(true);
|
|
|
|
return true;
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
|
|
|
LogError(std::current_exception());
|
2016-09-16 17:05:28 +02:00
|
|
|
return false;
|
2012-02-12 17:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-05-08 14:44:49 +02:00
|
|
|
DirectoryExists(Storage &storage, const Directory &directory) noexcept
|
2012-02-12 17:00:00 +01:00
|
|
|
{
|
2015-02-28 20:50:15 +01:00
|
|
|
StorageFileInfo info;
|
2016-09-16 17:05:28 +02:00
|
|
|
|
|
|
|
try {
|
2016-10-27 08:40:40 +02:00
|
|
|
info = storage.GetInfo(directory.GetPath(), true);
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2012-02-12 17:00:00 +01:00
|
|
|
return false;
|
2016-09-16 17:05:28 +02:00
|
|
|
}
|
2012-02-12 17:00:00 +01:00
|
|
|
|
2019-09-02 20:15:52 +02:00
|
|
|
return directory.IsReallyAFile()
|
2014-01-29 18:14:57 +01:00
|
|
|
? info.IsRegular()
|
|
|
|
: info.IsDirectory();
|
|
|
|
}
|
|
|
|
|
2016-10-27 08:40:40 +02:00
|
|
|
static StorageFileInfo
|
2014-02-05 17:03:43 +01:00
|
|
|
GetDirectoryChildInfo(Storage &storage, const Directory &directory,
|
2020-04-02 19:48:22 +02:00
|
|
|
std::string_view name_utf8)
|
2014-01-29 18:14:57 +01:00
|
|
|
{
|
|
|
|
const auto uri_utf8 = PathTraitsUTF8::Build(directory.GetPath(),
|
|
|
|
name_utf8);
|
2016-10-27 08:40:40 +02:00
|
|
|
return storage.GetInfo(uri_utf8.c_str(), true);
|
2012-02-12 17:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-05 17:03:43 +01:00
|
|
|
directory_child_is_regular(Storage &storage, const Directory &directory,
|
2020-04-02 19:48:22 +02:00
|
|
|
std::string_view name_utf8) noexcept
|
2016-09-16 17:05:28 +02:00
|
|
|
try {
|
2016-10-27 08:40:40 +02:00
|
|
|
return GetDirectoryChildInfo(storage, directory, name_utf8)
|
|
|
|
.IsRegular();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-09-16 17:05:28 +02:00
|
|
|
return false;
|
2012-02-12 17:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-05 17:03:43 +01:00
|
|
|
directory_child_access(Storage &storage, const Directory &directory,
|
2020-04-02 20:10:36 +02:00
|
|
|
std::string_view name, int mode) noexcept
|
2012-02-12 17:00:00 +01:00
|
|
|
{
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2013-02-02 15:25:13 +01:00
|
|
|
/* CheckAccess() is useless on WIN32 */
|
2014-01-29 18:14:57 +01:00
|
|
|
(void)storage;
|
2012-02-12 17:00:00 +01:00
|
|
|
(void)directory;
|
|
|
|
(void)name;
|
|
|
|
(void)mode;
|
|
|
|
return true;
|
|
|
|
#else
|
2014-01-29 18:14:57 +01:00
|
|
|
const auto path = storage.MapChildFS(directory.GetPath(), name);
|
2013-01-17 00:56:57 +01:00
|
|
|
if (path.IsNull())
|
2014-01-29 18:14:57 +01:00
|
|
|
/* does not point to local file: silently ignore the
|
|
|
|
check */
|
2012-02-12 17:00:00 +01:00
|
|
|
return true;
|
|
|
|
|
2013-02-02 15:25:13 +01:00
|
|
|
return CheckAccess(path, mode) || errno != EACCES;
|
2012-02-12 17:00:00 +01:00
|
|
|
#endif
|
|
|
|
}
|