summaryrefslogtreecommitdiffstats
path: root/source/core/slang-memory-file-system.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-10-06 10:27:50 -0400
committerGitHub <noreply@github.com>2022-10-06 10:27:50 -0400
commitd1e740d8b25e03a734093bd84b792eaf969649d1 (patch)
treebd19d69b54b00c9920dd6b02cc28d90dd8a639d5 /source/core/slang-memory-file-system.cpp
parentcf34d2830a3103b2b47a4140d27d054b797705f2 (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-memory-file-system.cpp')
-rw-r--r--source/core/slang-memory-file-system.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/source/core/slang-memory-file-system.cpp b/source/core/slang-memory-file-system.cpp
index 06c0a4ebe..a6bc05f24 100644
--- a/source/core/slang-memory-file-system.cpp
+++ b/source/core/slang-memory-file-system.cpp
@@ -9,6 +9,11 @@
namespace Slang
{
+MemoryFileSystem::MemoryFileSystem()
+{
+ m_rootEntry.initDirectory("/");
+}
+
void* MemoryFileSystem::getInterface(const Guid& guid)
{
if ( guid == ISlangUnknown::getTypeGuid() ||
@@ -40,15 +45,18 @@ void* MemoryFileSystem::castAs(const Guid& guid)
void MemoryFileSystem::_clear()
{
m_entries = Dictionary<String, Entry>();
- // Add the root
- Entry entry;
- entry.initDirectory(".");
- m_entries.Add(entry.m_canonicalPath, entry);
}
MemoryFileSystem::Entry* MemoryFileSystem::_getEntryFromCanonicalPath(const String& canonicalPath)
{
- return m_entries.TryGetValue(canonicalPath);
+ if (canonicalPath == toSlice("."))
+ {
+ return &m_rootEntry;
+ }
+ else
+ {
+ return m_entries.TryGetValue(canonicalPath);
+ }
}
MemoryFileSystem::Entry* MemoryFileSystem::_getEntryFromPath(const char* path, String* outPath)
@@ -141,7 +149,7 @@ SlangResult MemoryFileSystem::getPath(PathKind kind, const char* path, ISlangBlo
case PathKind::Canonical:
{
StringBuilder buffer;
- SLANG_RETURN_ON_FAIL(Path::simplifyAbsolute(path, buffer));
+ SLANG_RETURN_ON_FAIL(_getCanonical(path, buffer));
*outPath = StringBlob::moveCreate(buffer).detach();
return SLANG_OK;
}
@@ -197,7 +205,7 @@ SlangResult MemoryFileSystem::saveFileBlob(const char* path, ISlangBlob* dataBlo
SlangResult MemoryFileSystem::_getCanonical(const char* path, StringBuilder& outCanonicalPath)
{
StringBuilder canonicalPath;
- SLANG_RETURN_ON_FAIL(Path::simplifyAbsolute(UnownedStringSlice(path), outCanonicalPath));
+ SLANG_RETURN_ON_FAIL(Path::simplify(UnownedStringSlice(path), Path::SimplifyStyle::AbsoluteOnlyAndNoRoot, outCanonicalPath));
return SLANG_OK;
}
@@ -260,7 +268,7 @@ SlangResult MemoryFileSystem::remove(const char* path)
Entry* entry = _getEntryFromPath(path, &canonicalPath);
// If there is an entry and not the root of the file system
- if (entry && entry->m_canonicalPath != toSlice("."))
+ if (entry && entry != &m_rootEntry)
{
if (entry->m_type == SLANG_PATH_TYPE_DIRECTORY)
{