diff options
author | tim lindner <tlindner@macmess.org> | 2021-08-14 18:13:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-14 21:13:55 -0400 |
commit | 24b3acbce811010d93cebd951431e6e4734f1fa7 (patch) | |
tree | 36da776568dfb2ea9f7b92098131145b483c4246 /src/lib/util | |
parent | 6d6e53e1e2789ebc6050aa463219b681289a47d2 (diff) |
sdl ui: fix choosing the root path (#8443)
Diffstat (limited to 'src/lib/util')
-rw-r--r-- | src/lib/util/zippath.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp index 01d708bf2e1..023484010b8 100644 --- a/src/lib/util/zippath.cpp +++ b/src/lib/util/zippath.cpp @@ -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 } @@ -203,11 +205,15 @@ osd_file::error zippath_resolve(std::string_view path, osd::directory::entry::en bool went_up = false; do { - // 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); + 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 |