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

IFileSystem: Add a refresh method

And use it to force a device cache refresh
parent 2a9d5b4c
......@@ -54,5 +54,9 @@ namespace factory
/// \return A representation of the device, or nullptr if the device is currently unavailable.
///
virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& uuid ) = 0;
///
/// \brief refresh Will cause any FS cache to be refreshed.
///
virtual void refresh() = 0;
};
}
......@@ -88,6 +88,7 @@ void FsDiscoverer::reload()
void FsDiscoverer::checkDevices()
{
m_fsFactory->refresh();
auto devices = Device::fetchAll( m_dbConn );
for ( auto& d : devices )
{
......
......@@ -41,9 +41,6 @@ namespace factory
FileSystemFactory::FileSystemFactory()
{
static bool isCachePopulated = fs::Device::populateCache();
if ( isCachePopulated == false )
throw std::runtime_error( "Failed to populate device cache" );
}
std::shared_ptr<fs::IDirectory> FileSystemFactory::createDirectory( const std::string& path )
......@@ -75,6 +72,11 @@ std::shared_ptr<fs::IDevice> FileSystemFactory::createDevice( const std::string&
return fs::Device::fromUuid( uuid );
}
void FileSystemFactory::refresh()
{
fs::Device::populateCache();
}
}
......@@ -37,6 +37,7 @@ namespace factory
virtual std::shared_ptr<fs::IDirectory> createDirectory( const std::string& path ) override;
virtual std::unique_ptr<fs::IFile> createFile( const std::string& fileName ) override;
virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& uuid ) override;
virtual void refresh() override;
private:
std::unordered_map<std::string, std::shared_ptr<fs::IDirectory>> m_dirs;
......
......@@ -464,6 +464,8 @@ struct FileSystemFactory : public factory::IFileSystem
return *it;
}
virtual void refresh() override {}
std::shared_ptr<Device> device( const std::string& path )
{
std::shared_ptr<Device> ret;
......@@ -599,6 +601,10 @@ public:
{
return nullptr;
}
virtual void refresh() override
{
}
};
}
......
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