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

Folder: Fetch the fsFactory from the medialibrary instance

Instead of storing it in a static variable
parent fdb1247b
......@@ -42,8 +42,6 @@ namespace policy
int64_t Folder::* const FolderTable::PrimaryKey = &Folder::m_id;
}
std::shared_ptr<factory::IFileSystem> Folder::FsFactory;
Folder::Folder( MediaLibraryPtr ml, sqlite::Row& row )
: m_ml( ml )
{
......@@ -123,7 +121,7 @@ bool Folder::blacklist( MediaLibraryPtr ml, const std::string& fullPath )
// Let the foreign key destroy everything beneath this folder
destroy( ml, f->id() );
}
auto folderFs = FsFactory->createDirectory( fullPath );
auto folderFs = ml->fsFactory()->createDirectory( fullPath );
if ( folderFs == nullptr )
return false;
auto deviceFs = folderFs->device();
......@@ -140,11 +138,6 @@ bool Folder::blacklist( MediaLibraryPtr ml, const std::string& fullPath )
return sqlite::Tools::executeInsert( ml->getConn(), req, path, nullptr, true, device->id(), deviceFs->isRemovable() ) != 0;
}
void Folder::setFileSystemFactory( std::shared_ptr<factory::IFileSystem> fsFactory )
{
FsFactory = fsFactory;
}
std::shared_ptr<Folder> Folder::fromPath( MediaLibraryPtr ml, const std::string& fullPath )
{
return fromPath( ml, fullPath, false );
......@@ -157,7 +150,7 @@ std::shared_ptr<Folder> Folder::blacklistedFolder( MediaLibraryPtr ml, const std
std::shared_ptr<Folder> Folder::fromPath( MediaLibraryPtr ml, const std::string& fullPath, bool blacklisted )
{
auto folderFs = FsFactory->createDirectory( fullPath );
auto folderFs = ml->fsFactory()->createDirectory( fullPath );
if ( folderFs == nullptr )
return nullptr;
auto deviceFs = folderFs->device();
......@@ -201,7 +194,7 @@ const std::string& Folder::path() const
return m_fullPath;
auto device = Device::fetch( m_ml, m_deviceId );
auto deviceFs = FsFactory->createDevice( device->uuid() );
auto deviceFs = m_ml->fsFactory()->createDevice( device->uuid() );
m_deviceMountpoint = deviceFs->mountpoint();
m_fullPath = m_deviceMountpoint.get() + m_path;
return m_fullPath;
......
......@@ -63,12 +63,6 @@ public:
static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& path, int64_t parentId, Device& device, fs::IDevice& deviceFs );
static bool blacklist( MediaLibraryPtr ml, const std::string& fullPath );
static std::vector<std::shared_ptr<Folder>> fetchAll( MediaLibraryPtr ml, int64_t parentFolderId );
///
/// \brief setFileSystemFactory Sets a file system factory to be used when building IDevices
/// This is assumed to be called once, before any discovery/reloading process is launched.
/// \param fsFactory The factory to be used
///
static void setFileSystemFactory( std::shared_ptr<factory::IFileSystem> fsFactory );
static std::shared_ptr<Folder> fromPath(MediaLibraryPtr ml, const std::string& fullPath );
static std::shared_ptr<Folder> blacklistedFolder(MediaLibraryPtr ml, const std::string& fullPath );
......@@ -82,7 +76,6 @@ public:
bool isPresent() const;
private:
static std::shared_ptr<factory::IFileSystem> FsFactory;
static std::shared_ptr<Folder> fromPath( MediaLibraryPtr ml, const std::string& fullPath, bool includeBlacklisted );
private:
......
......@@ -205,7 +205,6 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
}
if ( m_fsFactory == nullptr )
m_fsFactory.reset( new factory::FileSystemFactory( m_deviceLister ) );
Folder::setFileSystemFactory( m_fsFactory );
if ( mkdir( thumbnailPath.c_str(), S_IRWXU ) != 0 )
{
if ( errno != EEXIST )
......@@ -596,6 +595,11 @@ IDeviceListerCb* MediaLibrary::setDeviceLister( DeviceListerPtr lister )
return static_cast<IDeviceListerCb*>( this );
}
std::shared_ptr<factory::IFileSystem> MediaLibrary::fsFactory() const
{
return m_fsFactory;
}
void MediaLibrary::discover( const std::string &entryPoint )
{
if ( m_discoverer != nullptr )
......
......@@ -128,6 +128,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;
public:
static const uint32_t DbModelVersion;
......
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