sdl ui: fix choosing the root path (#8443)

This commit is contained in:
tim lindner 2021-08-14 18:13:55 -07:00 committed by GitHub
parent 6d6e53e1e2
commit 24b3acbce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,14 +48,16 @@ int is_path_separator(char c)
bool is_root(std::string_view path)
{
// FIXME: get rid of the assumption that paths are DOS-like
#if defined(OSD_WINDOWS)
// skip drive letter
if (path.length() >= 2 && isalpha(path[0]) && (path[1] == ':'))
path.remove_prefix(2);
// skip path separators
return path.find_first_not_of(PATH_SEPARATOR) == std::string_view::npos;
#else
return (path.length() == 1) && (path[0] == '/');
#endif
}
@ -202,12 +204,16 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en
osd::directory::entry::entry_type current_entry_type = osd::directory::entry::entry_type::NONE;
bool went_up = false;
do
{
if (!is_root(apath))
{
// trim the path of trailing path separators
auto i = apath.find_last_not_of(PATH_SEPARATOR);
if (i == std::string::npos)
break;
apath = apath.substr(0, i + 1);
}
apath_trimmed = apath;
// stat the path