Commit 495c8396 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

factory: IFileSystem: Return an error when no devices are found

parent ab68f490
...@@ -61,7 +61,7 @@ namespace factory ...@@ -61,7 +61,7 @@ namespace factory
/// ///
/// \brief refresh Will cause any FS cache to be refreshed. /// \brief refresh Will cause any FS cache to be refreshed.
/// ///
virtual void refreshDevices() = 0; virtual bool refreshDevices() = 0;
}; };
} }
......
...@@ -99,7 +99,7 @@ std::shared_ptr<fs::IDevice> FileSystemFactory::createDeviceFromPath( const std: ...@@ -99,7 +99,7 @@ std::shared_ptr<fs::IDevice> FileSystemFactory::createDeviceFromPath( const std:
return res; return res;
} }
void FileSystemFactory::refreshDevices() bool FileSystemFactory::refreshDevices()
{ {
{ {
std::lock_guard<compat::Mutex> lock( m_mutex ); std::lock_guard<compat::Mutex> lock( m_mutex );
...@@ -110,6 +110,11 @@ void FileSystemFactory::refreshDevices() ...@@ -110,6 +110,11 @@ void FileSystemFactory::refreshDevices()
m_deviceCache = DeviceCacheMap{}; m_deviceCache = DeviceCacheMap{};
m_deviceCache.get().clear(); m_deviceCache.get().clear();
auto devices = m_deviceLister->devices(); auto devices = m_deviceLister->devices();
if ( devices.empty() == true )
{
LOG_ERROR( "Cannot continue with no devices" );
return false;
}
for ( const auto& d : devices ) for ( const auto& d : devices )
{ {
const auto& uuid = std::get<0>( d ); const auto& uuid = std::get<0>( d );
...@@ -117,6 +122,7 @@ void FileSystemFactory::refreshDevices() ...@@ -117,6 +122,7 @@ void FileSystemFactory::refreshDevices()
const auto removable = std::get<2>( d ); const auto removable = std::get<2>( d );
m_deviceCache.get().emplace( uuid, std::make_shared<fs::Device>( uuid, mountpoint, removable ) ); m_deviceCache.get().emplace( uuid, std::make_shared<fs::Device>( uuid, mountpoint, removable ) );
} }
return true;
} }
} }
......
...@@ -45,7 +45,7 @@ namespace factory ...@@ -45,7 +45,7 @@ namespace factory
virtual std::shared_ptr<fs::IDirectory> createDirectory( const std::string& path ) override; virtual std::shared_ptr<fs::IDirectory> createDirectory( const std::string& path ) override;
virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& uuid ) override; virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& uuid ) override;
virtual std::shared_ptr<fs::IDevice> createDeviceFromPath( const std::string& path ) override; virtual std::shared_ptr<fs::IDevice> createDeviceFromPath( const std::string& path ) override;
virtual void refreshDevices() override; virtual bool refreshDevices() override;
private: private:
std::unordered_map<std::string, std::shared_ptr<fs::IDirectory>> m_dirs; std::unordered_map<std::string, std::shared_ptr<fs::IDirectory>> m_dirs;
......
...@@ -177,7 +177,10 @@ struct FileSystemFactory : public factory::IFileSystem ...@@ -177,7 +177,10 @@ struct FileSystemFactory : public factory::IFileSystem
return *it; return *it;
} }
virtual void refreshDevices() override {} virtual bool refreshDevices() override
{
return false;
}
std::shared_ptr<Device> device( const std::string& path ) std::shared_ptr<Device> device( const std::string& path )
{ {
...@@ -315,8 +318,9 @@ public: ...@@ -315,8 +318,9 @@ public:
return nullptr; return nullptr;
} }
virtual void refreshDevices() override virtual bool refreshDevices() override
{ {
return false;
} }
}; };
......
Supports Markdown
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