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-memory-file-system.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'source/core/slang-memory-file-system.h') diff --git a/source/core/slang-memory-file-system.h b/source/core/slang-memory-file-system.h index 72bacf2bd..cd2701fe4 100644 --- a/source/core/slang-memory-file-system.h +++ b/source/core/slang-memory-file-system.h @@ -22,9 +22,6 @@ This is in contrast with an implementation that held items in directories 'objec would need to be traversed to find the item. Finding all of the items in a directory is very fast - it's all the items held in the the directory 'object'. -The implementation allows for 'implicit' directories. If we have a file "a/b" it's existance *implicitly* implies the existance of the -directory 'a'. This is similar to how archive file formats such as zip works. - TODO(JS): * We may want to make saveFile take a blob, or have a version that does. Doing so would allow the application to handle memory management around the blob. @@ -46,17 +43,20 @@ public: virtual SLANG_NO_THROW SlangResult SLANG_MCALL getFileUniqueIdentity(const char* path, ISlangBlob** uniqueIdentityOut) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType(const char* path, SlangPathType* pathTypeOut) SLANG_OVERRIDE; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getSimplifiedPath(const char* path, ISlangBlob** outSimplifiedPath) SLANG_OVERRIDE; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPath(PathKind pathKind, const char* path, ISlangBlob** outPath) SLANG_OVERRIDE; virtual SLANG_NO_THROW void SLANG_MCALL clearCache() SLANG_OVERRIDE {} virtual SLANG_NO_THROW SlangResult SLANG_MCALL enumeratePathContents(const char* path, FileSystemContentsCallBack callback, void* userData) SLANG_OVERRIDE; virtual SLANG_NO_THROW OSPathKind SLANG_MCALL getOSPathKind() SLANG_OVERRIDE { return OSPathKind::None; } // ISlangModifyableFileSystem virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveFile(const char* path, const void* data, size_t size) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveFileBlob(const char* path, ISlangBlob* dataBlob) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL remove(const char* path) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL createDirectory(const char* path) SLANG_OVERRIDE; + /// Ctor + MemoryFileSystem() { _clear(); } + protected: struct Entry @@ -109,7 +109,6 @@ protected: void* getInterface(const Guid& guid); void* getObject(const Guid& guid); - SlangResult _calcCanonicalPath(const char* path, StringBuilder& out); Entry* _getEntryFromPath(const char* path, String* outPath = nullptr); Entry* _getEntryFromCanonicalPath(const String& canonicalPath); /// Creates or returns a file entry for the given path. @@ -118,8 +117,15 @@ protected: /// Given the path returns the entry if it's a file, or returns an error SlangResult _loadFile(const char* path, Entry** outEntry); + /// Given a path returns a canonical path. + /// The canonical path must have *existing* parent paths. + SlangResult _getCanonicalWithExistingParent(const char* path, StringBuilder& canonicalPath); + + /// Given a path returns a canonical path. + SlangResult _getCanonical(const char* path, StringBuilder& canonicalPath); + /// Clear, ensures any backing memory is also freed - void _clear() { m_entries = Dictionary(); } + void _clear(); // Maps canonical paths to an entries (which could be files or directories) Dictionary m_entries; -- cgit v1.2.3