Commit 3d795426 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

filesystem: Cache Directory instances

This is mostly aimed at keeping them alive so we can check for
modifications & external storage unmounting
parent 940f1d59
......@@ -39,7 +39,13 @@ namespace factory
std::shared_ptr<fs::IDirectory> FileSystemFactory::createDirectory( const std::string& path )
{
return std::shared_ptr<fs::IDirectory>( new fs::Directory( path ) );
std::lock_guard<std::mutex> lock( m_mutex );
const auto it = m_dirs.find( path );
if ( it != end( m_dirs ) )
return it->second;
auto dir = std::make_shared<fs::Directory>( path );
m_dirs[path] = dir;
return dir;
}
std::unique_ptr<fs::IFile> FileSystemFactory::createFile(const std::string& fileName)
......
......@@ -24,6 +24,10 @@
#include "factory/IFileSystem.h"
#include <mutex>
#include <string>
#include <unordered_map>
namespace factory
{
class FileSystemFactory : public IFileSystem
......@@ -31,5 +35,9 @@ namespace factory
public:
virtual std::shared_ptr<fs::IDirectory> createDirectory( const std::string& path ) override;
virtual std::unique_ptr<fs::IFile> createFile( const std::string& fileName ) override;
private:
std::unordered_map<std::string, std::shared_ptr<fs::IDirectory>> m_dirs;
std::mutex m_mutex;
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment