Prefer BDVD over HDD0 in vfs::retrieve

This commit is contained in:
Eladash 2022-07-17 21:04:12 +03:00 committed by Ivan
parent d22b8b1d3a
commit dc48944979
2 changed files with 19 additions and 4 deletions

View File

@ -304,7 +304,7 @@ lv2_file::lv2_file(utils::serial& ar)
void lv2_file::save(utils::serial& ar)
{
USING_SERIALIZATION_VERSION(lv2_fs);
ar(name, mode, flags, type, lock, vfs::retrieve(real_path));
ar(name, mode, flags, type, lock, ensure(vfs::retrieve(real_path), FN(!x.empty())));
if (!(mp->flags & lv2_mp_flag::read_only) && flags & CELL_FS_O_ACCMODE)
{

View File

@ -388,13 +388,23 @@ std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std:
// Try to extract host root mount point name (if exists)
std::string_view host_root_name;
std::string result;
std::string result_dir;
for (const auto& [name, dir] : node->dirs)
{
mount_path->back() = name;
if (std::string res = vfs::retrieve(path, &dir, mount_path); !res.empty())
{
return res;
// Avoid app_home
// Prefer dev_bdvd over dev_hdd0
if (result.empty() || (name == "app_home") < (result_dir == "app_home") ||
(name == "dev_bdvd") > (result_dir == "dev_bdvd"))
{
result = std::move(res);
result_dir = name;
}
}
if (dir.path == "/"sv)
@ -403,6 +413,11 @@ std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std:
}
}
if (!result.empty())
{
return result;
}
mount_path->pop_back();
if (node->path.size() > 1 && path.starts_with(node->path))
@ -434,7 +449,7 @@ std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std:
{
// If failed to find mount point for path and /host_root is mounted
// Prepend "/host_root" to path and return the constructed string
std::string result{"/"};
result = "/";
for (const auto& name : *mount_path)
{
@ -449,7 +464,7 @@ std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std:
return result;
}
return {};
return result;
}
std::string vfs::escape(std::string_view name, bool escape_slash)