OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
LowercaseFileSystem Class Reference

#include <LowercaseFileSystem.h>

Inheritance diagram for LowercaseFileSystem:
FileSystem

Public Member Functions

 LowercaseFileSystem (FileSystem *base)
 
virtual ~LowercaseFileSystem ()
 
void refresh ()
 
- Public Member Functions inherited from FileSystem
 FileSystem ()=default
 
virtual ~FileSystem ()=default
 
bool exists (std::string_view path) const
 
bool exists (FileSystemPathView path) const
 
FileStat stat (std::string_view path) const
 
FileStat stat (FileSystemPathView path) const
 
std::vector< DirectoryEntryls (std::string_view path) const
 
std::vector< DirectoryEntryls (FileSystemPathView path) const
 
void ls (std::string_view path, std::vector< DirectoryEntry > *entries) const
 
void ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const
 
Blob read (std::string_view path) const
 
Blob read (FileSystemPathView path) const
 
void write (std::string_view path, const Blob &data)
 
void write (FileSystemPathView path, const Blob &data)
 
std::unique_ptr< InputStreamopenForReading (std::string_view path) const
 
std::unique_ptr< InputStreamopenForReading (FileSystemPathView path) const
 
std::unique_ptr< OutputStreamopenForWriting (std::string_view path)
 
std::unique_ptr< OutputStreamopenForWriting (FileSystemPathView path)
 
void rename (std::string_view srcPath, std::string_view dstPath)
 
void rename (FileSystemPathView srcPath, FileSystemPathView dstPath)
 
bool remove (std::string_view path)
 
bool remove (FileSystemPathView path)
 
std::string displayPath (std::string_view path) const
 
std::string displayPath (FileSystemPathView path) const
 

Private Types

using Node = FileSystemTrieNode< detail::LowercaseFileData >
 

Private Member Functions

virtual bool _exists (FileSystemPathView path) const override
 
virtual FileStat _stat (FileSystemPathView path) const override
 
virtual void _ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const override
 
virtual Blob _read (FileSystemPathView path) const override
 
virtual void _write (FileSystemPathView path, const Blob &data) override
 
virtual std::unique_ptr< InputStream_openForReading (FileSystemPathView path) const override
 
virtual std::unique_ptr< OutputStream_openForWriting (FileSystemPathView path) override
 
virtual void _rename (FileSystemPathView srcPath, FileSystemPathView dstPath) override
 
virtual bool _remove (FileSystemPathView path) override
 
virtual std::string _displayPath (FileSystemPathView path) const override
 
std::tuple< FileSystemPath, Node *, FileSystemPathViewwalk (FileSystemPathView path) const
 
void cacheLs (Node *node, FileSystemPathView basePath) const
 
void invalidateLs (Node *node) const
 
void cacheRemove (Node *node) const
 
void cacheInsert (Node *node, FileSystemPathView tail, FileType type) const
 
FileSystemPath locateForReading (FileSystemPathView path) const
 
std::tuple< FileSystemPath, Node *, FileSystemPathViewlocateForWriting (FileSystemPathView path)
 

Private Attributes

FileSystem_base = nullptr
 
FileSystemTrie< detail::LowercaseFileData_trie
 

Additional Inherited Members

- Protected Types inherited from FileSystem
template<class T >
using FileSystemTrieNode = detail::FileSystemTrieNode< T >
 
template<class T >
using FileSystemTrie = detail::FileSystemTrie< T >
 
virtual bool _exists (FileSystemPathView path) const =0
 
virtual FileStat _stat (FileSystemPathView path) const =0
 
virtual void _ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const =0
 
virtual Blob _read (FileSystemPathView path) const =0
 
virtual void _write (FileSystemPathView path, const Blob &data)=0
 
virtual std::unique_ptr< InputStream_openForReading (FileSystemPathView path) const =0
 
virtual std::unique_ptr< OutputStream_openForWriting (FileSystemPathView path)=0
 
virtual void _rename (FileSystemPathView srcPath, FileSystemPathView dstPath)
 
virtual bool _remove (FileSystemPathView path)=0
 
virtual std::string _displayPath (FileSystemPathView path) const =0
 

Detailed Description

Provides a lowercase view over another FileSystem:

Some notes on why it is designed the way it is designed.

Previous iteration was a writeable FS that was always up to date with the underlying FS (was checking timestamps for all parents in each call). The code was messy, it was O(N) on each call, and even after writing an implementation that actually worked, I hated it. Mostly because of the O(N) - which led to a recursive implementation of FileSystem::rename becoming O(N^2). It is possible to iron this out, but that would require to redo the FileSystem interface & expose the Directory abstraction directly. Which is just not worth it.

Next iteration was caching the whole file tree in constructor, but this was blowing up spectacularly when constructed for /. Thus, we're now caching lazily.

The important point about the implementation is that there is no amplification of the number of calls into the underlying file system. Each of the methods in LowercaseFileSystem calls into the underlying file system at most once.

Member Typedef Documentation

◆ Node

Constructor & Destructor Documentation

◆ LowercaseFileSystem()

LowercaseFileSystem::LowercaseFileSystem ( FileSystem base)
explicit

◆ ~LowercaseFileSystem()

LowercaseFileSystem::~LowercaseFileSystem ( )
virtualdefault

Member Function Documentation

◆ _displayPath()

std::string LowercaseFileSystem::_displayPath ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _exists()

bool LowercaseFileSystem::_exists ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _ls()

void LowercaseFileSystem::_ls ( FileSystemPathView  path,
std::vector< DirectoryEntry > *  entries 
) const
overrideprivatevirtual

Implements FileSystem.

◆ _openForReading()

std::unique_ptr< InputStream > LowercaseFileSystem::_openForReading ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _openForWriting()

std::unique_ptr< OutputStream > LowercaseFileSystem::_openForWriting ( FileSystemPathView  path)
overrideprivatevirtual

Implements FileSystem.

◆ _read()

Blob LowercaseFileSystem::_read ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _remove()

bool LowercaseFileSystem::_remove ( FileSystemPathView  path)
overrideprivatevirtual

Implements FileSystem.

◆ _rename()

void LowercaseFileSystem::_rename ( FileSystemPathView  srcPath,
FileSystemPathView  dstPath 
)
overrideprivatevirtual

Reimplemented from FileSystem.

◆ _stat()

FileStat LowercaseFileSystem::_stat ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _write()

void LowercaseFileSystem::_write ( FileSystemPathView  path,
const Blob data 
)
overrideprivatevirtual

Implements FileSystem.

◆ cacheInsert()

void LowercaseFileSystem::cacheInsert ( Node node,
FileSystemPathView  tail,
FileType  type 
) const
private

◆ cacheLs()

void LowercaseFileSystem::cacheLs ( Node node,
FileSystemPathView  basePath 
) const
private

◆ cacheRemove()

void LowercaseFileSystem::cacheRemove ( Node node) const
private

◆ invalidateLs()

void LowercaseFileSystem::invalidateLs ( Node node) const
private

◆ locateForReading()

FileSystemPath LowercaseFileSystem::locateForReading ( FileSystemPathView  path) const
private

◆ locateForWriting()

std::tuple< FileSystemPath, LowercaseFileSystem::Node *, FileSystemPathView > LowercaseFileSystem::locateForWriting ( FileSystemPathView  path)
private

◆ refresh()

void LowercaseFileSystem::refresh ( )

◆ walk()

std::tuple< FileSystemPath, LowercaseFileSystem::Node *, FileSystemPathView > LowercaseFileSystem::walk ( FileSystemPathView  path) const
private

Member Data Documentation

◆ _base

FileSystem* LowercaseFileSystem::_base = nullptr
private

◆ _trie

FileSystemTrie<detail::LowercaseFileData> LowercaseFileSystem::_trie
mutableprivate

The documentation for this class was generated from the following files: