Emulation: Fix boot path resolving

* Fix /dev_flash executables path arg. (/host_root is wrong for it)
* Fix usage of /host_root for homebrew applications when it is not mounted, use /app_home.
* Fix path source detection. (don't get fooled by path slashes repetitions, symlinks, '.', ".." and ('\' on Windows))
* Unescape tail of /dev_hdd0 paths.
This commit is contained in:
Eladash 2021-04-06 23:16:58 +03:00 committed by Ivan
parent 95725bf7fc
commit 49c5ce30cc
7 changed files with 70 additions and 124 deletions

View file

@ -1703,110 +1703,6 @@ bool fs::remove_all(const std::string& path, bool remove_root)
return true;
}
std::string fs::escape_path(std::string_view path)
{
std::string real; real.resize(path.size());
auto get_char = [&](usz& from, usz& to, usz count)
{
std::memcpy(&real[to], &path[from], count);
from += count, to += count;
};
usz i = 0, j = -1, pos_nondelim = 0, after_delim = 0;
if (i < path.size())
{
j = 0;
}
for (; i < path.size();)
{
real[j] = path[i];
#ifdef _Win32
if (real[j] == '\\')
{
real[j] = '/';
}
#endif
// If the current character was preceeded by a delimiter special treatment is required:
// If another deleimiter is encountered, remove it (do not write it to output string)
// Otherwise test if it is a "." or ".." sequence.
if (std::exchange(after_delim, path[i] == delim[0] || path[i] == delim[1]))
{
if (!after_delim)
{
if (real[j] == '.')
{
if (i + 1 == path.size())
{
break;
}
get_char(i, j, 1);
switch (real[j])
{
case '.':
{
bool remove_element = true;
usz k = 1;
for (; k + i != path.size(); k++)
{
switch (path[i + k])
{
case '.': continue;
case delim[0]: case delim[1]: break;
default: remove_element = false; break;
}
}
if (remove_element)
{
if (i == 1u)
{
j = pos_nondelim;
real[j] = '\0';// Ensure termination at this posistion
after_delim = true;
i += k;
continue;
}
}
get_char(i, j, k);
continue;
}
case '/':
{
i++;
after_delim = true;
continue;
}
default: get_char(i, j, 1); continue;
}
}
pos_nondelim = j;
get_char(i, j, 1);
}
else
{
i++;
}
}
else
{
get_char(i, j, 1);
}
}
if (j != umax && (real[j] == delim[0] || real[j] == delim[1])) j--; // Do not include a delmiter at the end
real.resize(j + 1);
return real;
}
u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
{
u64 result = 0;