From 0b51ea6bb54b1d8a12695ccc2c259fd591069791 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 3 Oct 2022 21:09:16 -0400 Subject: IMutableFileSystem::saveFileBlob (#2427) * #include an absolute path didn't work - because paths were taken to always be relative. * Remove ref count for Entry in RiffFileSystem. Free up backing Entry types (to work around Dictionary not doing this). * Some small improvements to RiffFileSystem. * Add testing for file systems. * Split out MemoryFileSystem. * Add some documentation around different FileSystems. * Small tiry up - removing unused headers, fixing some comments. Use StringBlob::moveCreate where appropriate. * Small improvement to MemoryFileSystem. Improve documentation comments a little. * Added PathKind * * Make MemoryFileSystem not have implicit directories * Make RelativeFileSystem only allow access to files in file system (kind of like chroot) * Added Path::simplifyAbsolute * Special handling for root of MemoryFileSystem * Improvements around paths for different impls * More improvements around RelativeFileSystem. Special case root handling. * Test archive serialization. Move testinf from compression. Remove the implicit directory test -> doesn't work on all file systems. * Small optimization that removes need for check for a parent unless an item is being *created*. * Add implicit path testing. * Add support for saveFileBlob Add testing for saveFileBlob * Removed TemporaryFileSet Added PlatformUtil::outputDebugMessage * Some small improvements around RelativeFileSystem. * Split out ImplicitDirectoryCollector so can use without requiring compression systems. * Split out StringSliceIndexMap into own files. --- source/core/slang-io.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/core/slang-io.cpp') diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index ef260f088..b25d5562d 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -419,6 +419,38 @@ namespace Slang return false; } + /* static */SlangResult Path::simplifyAbsolute(const UnownedStringSlice& path, StringBuilder& outPath) + { + if (path.getLength() == 0) + { + return SLANG_FAIL; + } + + List splitPath; + Path::split(UnownedStringSlice(path), splitPath); + + // If the first part of a path is "", it means path of form "/some/path". Turn into "some/path". + if (splitPath.getCount() > 1 && splitPath[0].getLength() == 0) + { + splitPath.removeAt(0); + } + + Path::simplify(splitPath); + + // If it has a relative part then it's not absolute + if (splitPath.indexOf(UnownedStringSlice::fromLiteral("..")) >= 0) + { + return SLANG_E_NOT_FOUND; + } + + // We allow splitPath.getCount() == 0, because + // the original path could have been '.' or './.' + // Special handling for this is in join + + Path::join(splitPath.getBuffer(), splitPath.getCount(), outPath); + return SLANG_OK; + } + /* static */void Path::simplify(List& ioSplit) { // Strictly speaking we could do something about case on platforms like window, but here we won't worry about that -- cgit v1.2.3