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

MediaLibrary: Add support for multiple fs factories

parent dc0919b8
......@@ -131,7 +131,10 @@ bool Folder::blacklist( MediaLibraryPtr ml, const std::string& fullPath )
// Let the foreign key destroy everything beneath this folder
destroy( ml, f->id() );
}
auto folderFs = ml->fsFactory()->createDirectory( fullPath );
auto fsFactory = ml->fsFactoryForPath( fullPath );
if ( fsFactory == nullptr )
return false;
auto folderFs = fsFactory->createDirectory( fullPath );
if ( folderFs == nullptr )
return false;
auto deviceFs = folderFs->device();
......@@ -162,7 +165,10 @@ std::shared_ptr<Folder> Folder::blacklistedFolder( MediaLibraryPtr ml, const std
std::shared_ptr<Folder> Folder::fromPath( MediaLibraryPtr ml, const std::string& fullPath, BannedType bannedType )
{
auto folderFs = ml->fsFactory()->createDirectory( fullPath );
auto fsFactory = ml->fsFactoryForPath( fullPath );
if ( fsFactory == nullptr )
return nullptr;
auto folderFs = fsFactory->createDirectory( fullPath );
if ( folderFs == nullptr )
return nullptr;
auto deviceFs = folderFs->device();
......@@ -218,7 +224,9 @@ const std::string& Folder::path() const
return m_fullPath;
auto device = Device::fetch( m_ml, m_deviceId );
auto deviceFs = m_ml->fsFactory()->createDevice( device->uuid() );
auto fsFactory = m_ml->fsFactoryForPath( m_fullPath );
assert( fsFactory != nullptr );
auto deviceFs = fsFactory->createDevice( device->uuid() );
m_deviceMountpoint = deviceFs->mountpoint();
m_fullPath = m_deviceMountpoint.get() + m_path;
return m_fullPath;
......
......@@ -209,8 +209,10 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
return false;
}
}
if ( m_fsFactory == nullptr )
m_fsFactory.reset( new factory::FileSystemFactory( m_deviceLister ) );
if ( m_fsFactories.empty() == true )
{
m_fsFactories.push_back( std::make_shared<factory::FileSystemFactory>( m_deviceLister ) );
}
#ifdef _WIN32
if ( mkdir( thumbnailPath.c_str() ) != 0 )
#else
......@@ -260,7 +262,10 @@ MediaPtr MediaLibrary::media( int64_t mediaId ) const
MediaPtr MediaLibrary::media( const std::string& mrl ) const
{
auto device = m_fsFactory->createDeviceFromPath( mrl );
auto fsFactory = fsFactoryForPath( mrl );
if ( fsFactory == nullptr )
return nullptr;
auto device = fsFactory->createDeviceFromPath( mrl );
if ( device == nullptr )
{
LOG_WARN( "Failed to create a device associated with mrl ", mrl );
......@@ -577,7 +582,8 @@ void MediaLibrary::startParser()
void MediaLibrary::startDiscoverer()
{
m_discoverer.reset( new DiscovererWorker( this ) );
m_discoverer->addDiscoverer( std::unique_ptr<IDiscoverer>( new FsDiscoverer( m_fsFactory, this, m_callback ) ) );
for ( const auto& fsFactory : m_fsFactories )
m_discoverer->addDiscoverer( std::unique_ptr<IDiscoverer>( new FsDiscoverer( fsFactory, this, m_callback ) ) );
m_discoverer->reload();
}
......@@ -655,9 +661,14 @@ IDeviceListerCb* MediaLibrary::setDeviceLister( DeviceListerPtr lister )
return static_cast<IDeviceListerCb*>( this );
}
std::shared_ptr<factory::IFileSystem> MediaLibrary::fsFactory() const
std::shared_ptr<factory::IFileSystem> MediaLibrary::fsFactoryForPath( const std::string& path ) const
{
return m_fsFactory;
for ( const auto& f : m_fsFactories )
{
if ( f->isPathSupported( path ) )
return f;
}
return nullptr;
}
void MediaLibrary::discover( const std::string &entryPoint )
......@@ -699,14 +710,28 @@ void MediaLibrary::setLogger( ILogger* logger )
Log::SetLogger( logger );
}
void MediaLibrary::onDevicePlugged( const std::string&, const std::string& )
void MediaLibrary::onDevicePlugged( const std::string&, const std::string& mountpoint )
{
m_fsFactory->refreshDevices();
for ( const auto& fsFactory : m_fsFactories )
{
if ( fsFactory->isPathSupported( "file://" ) )
{
fsFactory->refreshDevices();
break;
}
}
}
void MediaLibrary::onDeviceUnplugged( const std::string& )
{
m_fsFactory->refreshDevices();
for ( const auto& fsFactory : m_fsFactories )
{
if ( fsFactory->isPathSupported( "file://" ) )
{
fsFactory->refreshDevices();
break;
}
}
}
}
......@@ -131,7 +131,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
std::shared_ptr<ModificationNotifier> getNotifier() const;
virtual IDeviceListerCb* setDeviceLister( DeviceListerPtr lister ) override;
std::shared_ptr<factory::IFileSystem> fsFactory() const;
std::shared_ptr<factory::IFileSystem> fsFactoryForPath( const std::string& path ) const;
public:
static const uint32_t DbModelVersion;
......@@ -156,7 +156,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
protected:
std::unique_ptr<SqliteConnection> m_dbConnection;
std::shared_ptr<factory::IFileSystem> m_fsFactory;
std::vector<std::shared_ptr<factory::IFileSystem>> m_fsFactories;
std::string m_thumbnailPath;
IMediaLibraryCb* m_callback;
DeviceListerPtr m_deviceLister;
......
......@@ -104,7 +104,7 @@ std::shared_ptr<Device> MediaLibraryTester::addDevice( const std::string& uuid,
void MediaLibraryTester::setFsFactory(std::shared_ptr<factory::IFileSystem> fsFactory)
{
m_fsFactory = fsFactory;
m_fsFactories.push_back( fsFactory );
}
void MediaLibraryTester::deleteTrack( int64_t trackId )
......
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