mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
File.cpp: revert get_parent_dir change
This commit is contained in:
parent
0a0ef50caf
commit
bcbce5dd48
2 changed files with 41 additions and 12 deletions
|
@ -387,24 +387,53 @@ shared_ptr<fs::device_base> fs::set_virtual_device(const std::string& name, shar
|
||||||
|
|
||||||
std::string fs::get_parent_dir(std::string_view path, u32 parent_level)
|
std::string fs::get_parent_dir(std::string_view path, u32 parent_level)
|
||||||
{
|
{
|
||||||
std::string normalized_path = std::filesystem::path(path).lexically_normal().string();
|
std::string_view result = path;
|
||||||
|
|
||||||
#ifdef _WIN32
|
// Number of path components to remove
|
||||||
std::replace(normalized_path.begin(), normalized_path.end(), '\\', '/');
|
usz to_remove = parent_level;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (normalized_path.ends_with('/'))
|
while (to_remove--)
|
||||||
normalized_path.pop_back();
|
|
||||||
|
|
||||||
while (parent_level--)
|
|
||||||
{
|
{
|
||||||
if (const auto pos = normalized_path.find_last_of('/'); pos != umax)
|
// Trim contiguous delimiters at the end
|
||||||
normalized_path = normalized_path.substr(0, pos);
|
if (usz sz = result.find_last_not_of(delim) + 1)
|
||||||
|
{
|
||||||
|
result = result.substr(0, sz);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto elem = result.substr(result.find_last_of(delim) + 1);
|
||||||
|
|
||||||
|
if (elem.empty() || elem.size() == result.size())
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalized_path.empty() ? "/" : normalized_path;
|
if (elem == ".")
|
||||||
|
{
|
||||||
|
to_remove += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elem == "..")
|
||||||
|
{
|
||||||
|
to_remove += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.remove_suffix(elem.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usz sz = result.find_last_not_of(delim) + 1)
|
||||||
|
{
|
||||||
|
result = result.substr(0, sz);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fs::stat(const std::string& path, stat_t& info)
|
bool fs::stat(const std::string& path, stat_t& info)
|
||||||
|
|
|
@ -165,7 +165,7 @@ namespace fs
|
||||||
// Set virtual device with specified name (nullptr for deletion)
|
// Set virtual device with specified name (nullptr for deletion)
|
||||||
shared_ptr<device_base> set_virtual_device(const std::string& name, shared_ptr<device_base> device);
|
shared_ptr<device_base> set_virtual_device(const std::string& name, shared_ptr<device_base> device);
|
||||||
|
|
||||||
// Try to get normalized parent directory
|
// Try to get parent directory
|
||||||
std::string get_parent_dir(std::string_view path, u32 parent_level = 1);
|
std::string get_parent_dir(std::string_view path, u32 parent_level = 1);
|
||||||
|
|
||||||
// Get file information
|
// Get file information
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue