diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-10-06 10:27:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-06 10:27:50 -0400 |
| commit | d1e740d8b25e03a734093bd84b792eaf969649d1 (patch) | |
| tree | bd19d69b54b00c9920dd6b02cc28d90dd8a639d5 /source/core/slang-zip-file-system.cpp | |
| parent | cf34d2830a3103b2b47a4140d27d054b797705f2 (diff) | |
Improvements around absolute paths and file systems (#2433)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add handling for root paths.
* Fixes around absolute paths.
* Add SimplifyStyle
* Remove unrequire include.
* Fix some details around RelativeFileSystem canonical paths.
* For MemoryFileSystem make sure "/a" and "a" maps to same canonical path.
* Add test for canonicalPath.
* Improve comment.
* More testing around canonical paths.
Diffstat (limited to 'source/core/slang-zip-file-system.cpp')
| -rw-r--r-- | source/core/slang-zip-file-system.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/source/core/slang-zip-file-system.cpp b/source/core/slang-zip-file-system.cpp index 28782dba7..011fd2aab 100644 --- a/source/core/slang-zip-file-system.cpp +++ b/source/core/slang-zip-file-system.cpp @@ -418,15 +418,8 @@ SlangResult ZipFileSystemImpl::_requireMode(Mode newMode) SlangResult ZipFileSystemImpl::_getFixedPath(const char* path, String& outPath) { - String simplifiedPath = Path::simplify(UnownedStringSlice(path)); - // Can simplify to just ., thats okay, if it otherwise has something relative it means it couldn't be simplified into the - // contents of the archive - if (simplifiedPath != "." && Path::hasRelativeElement(simplifiedPath)) - { - // If it still has a relative element, then it must be 'outside' of the archive - return SLANG_E_NOT_FOUND; - } - + StringBuilder simplifiedPath; + SLANG_RETURN_ON_FAIL(Path::simplify(path, Path::SimplifyStyle::AbsoluteOnlyAndNoRoot, simplifiedPath)); outPath = simplifiedPath; return SLANG_OK; } @@ -528,17 +521,27 @@ SlangResult ZipFileSystemImpl::getPath(PathKind pathKind, const char* path, ISla case PathKind::Display: case PathKind::Canonical: { - mz_uint index; - SLANG_RETURN_ON_FAIL(_findEntryIndex(path, index)); + // Get the fixed path + String fixedPath; + SLANG_RETURN_ON_FAIL(_getFixedPath(path, fixedPath)); - mz_zip_archive_file_stat fileStat; - if (!mz_zip_reader_file_stat(&m_archive, index, &fileStat)) + // See if we can find in the zip explicitly + mz_uint index; + if (SLANG_SUCCEEDED(_findEntryIndexFromFixedPath(fixedPath, index))) { - return SLANG_FAIL; + mz_zip_archive_file_stat fileStat; + if (!mz_zip_reader_file_stat(&m_archive, index, &fileStat)) + { + return SLANG_FAIL; + } + + // Use the path in the archive itself + *outPath = StringUtil::createStringBlob(fileStat.m_filename).detach(); + return SLANG_OK; } - // Use the path in the archive itself - *outPath = StringUtil::createStringBlob(fileStat.m_filename).detach(); + // Else output the fixed path + *outPath = StringUtil::createStringBlob(fixedPath).detach(); return SLANG_OK; } case PathKind::Simplified: |
