util/zippath.cpp: Made behaviour of trying to open things inside archives a bit more consistent, fixed another bug with root paths.
This commit is contained in:
parent
870b91da8c
commit
75f2f4d35a
@ -208,10 +208,11 @@ std::error_condition zippath_resolve(std::string_view path, osd::directory::entr
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// trim the path of trailing path separators
|
// trim the path of trailing path separators
|
||||||
auto i = apath.find_last_not_of(PATH_SEPARATOR);
|
auto const i = apath.find_last_not_of(PATH_SEPARATOR);
|
||||||
if (i == std::string::npos)
|
if (i != std::string::npos)
|
||||||
|
apath.erase(std::max<decltype(i)>(i + 1, 2)); // don't erase drive letter
|
||||||
|
else if (!is_root(apath))
|
||||||
break;
|
break;
|
||||||
apath = apath.erase(std::max<decltype(i)>(i + 1, 2)); // don't erase drive letter
|
|
||||||
|
|
||||||
apath_trimmed = apath;
|
apath_trimmed = apath;
|
||||||
|
|
||||||
@ -667,7 +668,7 @@ std::error_condition zippath_fopen(std::string_view filename, uint32_t openflags
|
|||||||
file = nullptr;
|
file = nullptr;
|
||||||
|
|
||||||
// loop through
|
// loop through
|
||||||
while (!file && !mainpath.empty() && ((openflags == OPEN_FLAG_READ) || subpath.empty()))
|
while (!file && !mainpath.empty())
|
||||||
{
|
{
|
||||||
// is the mainpath a ZIP path?
|
// is the mainpath a ZIP path?
|
||||||
if (is_zip_file(mainpath) || is_7z_file(mainpath))
|
if (is_zip_file(mainpath) || is_7z_file(mainpath))
|
||||||
@ -676,25 +677,36 @@ std::error_condition zippath_fopen(std::string_view filename, uint32_t openflags
|
|||||||
std::error_condition const ziperr = is_zip_file(mainpath) ? archive_file::open_zip(mainpath, zip) : archive_file::open_7z(mainpath, zip);
|
std::error_condition const ziperr = is_zip_file(mainpath) ? archive_file::open_zip(mainpath, zip) : archive_file::open_7z(mainpath, zip);
|
||||||
if (!ziperr)
|
if (!ziperr)
|
||||||
{
|
{
|
||||||
// it is a zip file - error if we're not opening for reading
|
|
||||||
if (openflags != OPEN_FLAG_READ)
|
|
||||||
{
|
|
||||||
filerr = std::errc::permission_denied;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
osd::directory::entry::entry_type entry_type;
|
osd::directory::entry::entry_type entry_type;
|
||||||
int header;
|
int header;
|
||||||
if (!subpath.empty())
|
if (!subpath.empty())
|
||||||
|
{
|
||||||
header = zippath_find_sub_path(*zip, subpath, entry_type);
|
header = zippath_find_sub_path(*zip, subpath, entry_type);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
header = zip->first_file();
|
header = zip->first_file();
|
||||||
|
entry_type = osd::directory::entry::entry_type::FILE;
|
||||||
|
}
|
||||||
|
|
||||||
if (header < 0)
|
if (header < 0)
|
||||||
{
|
{
|
||||||
|
if (openflags & OPEN_FLAG_CREATE)
|
||||||
|
filerr = std::errc::permission_denied;
|
||||||
|
else
|
||||||
filerr = std::errc::no_such_file_or_directory;
|
filerr = std::errc::no_such_file_or_directory;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
else if (osd::directory::entry::entry_type::DIR == entry_type)
|
||||||
|
{
|
||||||
|
filerr = std::errc::is_a_directory;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
else if (openflags & OPEN_FLAG_WRITE)
|
||||||
|
{
|
||||||
|
filerr = std::errc::permission_denied;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
// attempt to read the file
|
// attempt to read the file
|
||||||
filerr = create_core_file_from_zip(*zip, file);
|
filerr = create_core_file_from_zip(*zip, file);
|
||||||
|
Loading…
Reference in New Issue
Block a user