mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
Use path_append instead of operator + to concat paths
This allows to cleanly prevent double // slashes when appending paths While this should not be a problem, Windows seems to have problems with such paths when paths are very long - and preventing this is trivial enough.
This commit is contained in:
parent
b591633cb9
commit
974bce19ed
1 changed files with 24 additions and 3 deletions
|
@ -177,6 +177,27 @@ static fs::error to_error(int e)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static std::string path_append(std::string_view path, std::string_view more)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
if (const size_t src_slash_pos = path.find_last_not_of('/'); src_slash_pos != path.npos)
|
||||||
|
{
|
||||||
|
path.remove_suffix(path.length() - src_slash_pos - 1);
|
||||||
|
result = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push_back('/');
|
||||||
|
|
||||||
|
if (const size_t dst_slash_pos = more.find_first_not_of('/'); dst_slash_pos != more.npos)
|
||||||
|
{
|
||||||
|
more.remove_prefix(dst_slash_pos);
|
||||||
|
result.append(more);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
namespace fs
|
namespace fs
|
||||||
{
|
{
|
||||||
thread_local error g_tls_error = error::ok;
|
thread_local error g_tls_error = error::ok;
|
||||||
|
@ -1586,7 +1607,7 @@ bool fs::remove_all(const std::string& path, bool remove_root)
|
||||||
|
|
||||||
if (entry.is_directory == false)
|
if (entry.is_directory == false)
|
||||||
{
|
{
|
||||||
if (!remove_file(path + '/' + entry.name))
|
if (!remove_file(path_append(path, entry.name)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1594,7 +1615,7 @@ bool fs::remove_all(const std::string& path, bool remove_root)
|
||||||
|
|
||||||
if (entry.is_directory == true)
|
if (entry.is_directory == true)
|
||||||
{
|
{
|
||||||
if (!remove_all(path + '/' + entry.name))
|
if (!remove_all(path_append(path, entry.name)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1632,7 +1653,7 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
|
||||||
|
|
||||||
if (entry.is_directory == true)
|
if (entry.is_directory == true)
|
||||||
{
|
{
|
||||||
result += get_dir_size(path + '/' + entry.name, rounding_alignment);
|
result += get_dir_size(path_append(path, entry.name), rounding_alignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue