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.h | 62 +++++--------------------------------------------- 1 file changed, 6 insertions(+), 56 deletions(-) (limited to 'source/core/slang-io.h') diff --git a/source/core/slang-io.h b/source/core/slang-io.h index aa4ccae42..acdcd0124 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -126,6 +126,12 @@ namespace Slang static String simplify(const UnownedStringSlice& path); static String simplify(const String& path) { return simplify(path.getUnownedSlice()); } + /// Given a path simplifies it such the the resultant path is absolute (ie contains no . or ..) + /// Can return '.' as the path as the directory 'root'. + static SlangResult simplifyAbsolute(const UnownedStringSlice& path, StringBuilder& outPath); + static SlangResult simplifyAbsolute(const String& path, StringBuilder& outPath) { return simplifyAbsolute(path.getUnownedSlice(), outPath); } + static SlangResult simplifyAbsolute(const char* path, StringBuilder& outPath) { return simplifyAbsolute(UnownedStringSlice(path), outPath); } + /// Simplifies the path split up static void simplify(List& ioSplit); @@ -186,62 +192,6 @@ namespace Slang static bool isSafeURIChar(char ch); }; - // Helper class to clean up temporary files on dtor - class TemporaryFileSet: public RefObject - { - public: - typedef RefObject Super; - typedef TemporaryFileSet ThisType; - - void remove(const String& path) - { - if (const Index index = m_paths.indexOf(path) >= 0) - { - m_paths.removeAt(index); - } - } - - void add(const String& path) - { - if (m_paths.indexOf(path) < 0) - { - m_paths.add(path); - } - } - void add(const List& paths) - { - for (const auto& path : paths) - { - add(path); - } - } - void clear() - { - m_paths.clear(); - } - - void swapWith(ThisType& rhs) - { - m_paths.swapWith(rhs.m_paths); - } - - ~TemporaryFileSet() - { - for (const auto& path : m_paths) - { - File::remove(path); - } - } - /// Default Ctor - TemporaryFileSet() {} - - List m_paths; - - private: - // Disable ctor/assignment - TemporaryFileSet(const ThisType& rhs) = delete; - void operator=(const ThisType& rhs) = delete; - }; } #endif -- cgit v1.2.3