mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 13:31:27 +12:00
Fix fs::delim type, fix "." and ".." processing in fs::get_parent_dir (#8975)
* Fix fs::delim type * Fix fs::get_parent_dir: "." and ".." processing
This commit is contained in:
parent
0f67c68993
commit
8ad36e2526
2 changed files with 8 additions and 16 deletions
|
@ -322,20 +322,12 @@ std::shared_ptr<fs::device_base> fs::set_virtual_device(const std::string& name,
|
||||||
|
|
||||||
std::string fs::get_parent_dir(const std::string& path)
|
std::string fs::get_parent_dir(const std::string& path)
|
||||||
{
|
{
|
||||||
// Search upper bound (set to the last character, npos for empty string)
|
// Get (basically) processed path
|
||||||
auto last = path.size() - 1;
|
const auto real_path = fs::escape_path(path);
|
||||||
|
|
||||||
while (true)
|
const auto pos = real_path.find_last_of(delim);
|
||||||
{
|
|
||||||
const auto pos = path.find_last_of(delim, last, sizeof(delim) - 1);
|
|
||||||
|
|
||||||
// Contiguous slashes are ignored at the end
|
return real_path.substr(0, pos == umax ? 0 : pos);
|
||||||
if (std::exchange(last, pos - 1) != pos)
|
|
||||||
{
|
|
||||||
// Return empty string if the path doesn't contain at least 2 elements
|
|
||||||
return path.substr(0, pos != umax && path.find_last_not_of(delim, pos, sizeof(delim) - 1) != umax ? pos : 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fs::stat(const std::string& path, stat_t& info)
|
bool fs::stat(const std::string& path, stat_t& info)
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
namespace fs
|
namespace fs
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static constexpr auto delim = "/\\";
|
static constexpr auto& delim = "/\\";
|
||||||
static constexpr auto wdelim = L"/\\";
|
static constexpr auto& wdelim = L"/\\";
|
||||||
using native_handle = void*;
|
using native_handle = void*;
|
||||||
#else
|
#else
|
||||||
static constexpr auto delim = "/";
|
static constexpr auto& delim = "/";
|
||||||
static constexpr auto wdelim = L"/";
|
static constexpr auto& wdelim = L"/";
|
||||||
using native_handle = int;
|
using native_handle = int;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue