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

Allow a specific directory to be reloaded

parent 8a89cfa3
......@@ -38,6 +38,7 @@ public:
//a discoverer thread
virtual bool discover( const std::string& entryPoint ) = 0;
virtual void reload() = 0;
virtual void reload( const std::string& entryPoint ) = 0;
};
#endif // IDISCOVERER_H
......@@ -54,8 +54,8 @@ public:
virtual void onDiscoveryStarted( const std::string& entryPoint ) = 0;
virtual void onDiscoveryCompleted( const std::string& entryPoint ) = 0;
virtual void onReloadStarted() = 0;
virtual void onReloadCompleted() = 0;
virtual void onReloadStarted( const std::string& entryPoint ) = 0;
virtual void onReloadCompleted( const std::string& entryPoint ) = 0;
/**
* @brief onParsingStatsUpdated Called when the parser statistics are updated
*
......@@ -129,6 +129,7 @@ class IMediaLibrary
*/
virtual void resumeBackgroundOperations() = 0;
virtual void reload() = 0;
virtual void reload( const std::string& entryPoint ) = 0;
};
extern "C"
......
......@@ -438,6 +438,12 @@ void MediaLibrary::reload()
m_discoverer->reload();
}
void MediaLibrary::reload( const std::string& entryPoint )
{
if ( m_discoverer != nullptr )
m_discoverer->reload( entryPoint );
}
void MediaLibrary::pauseBackgroundOperations()
{
if ( m_parser != nullptr )
......
......@@ -89,6 +89,7 @@ class MediaLibrary : public IMediaLibrary
virtual void setLogger( ILogger* logger ) override;
//Temporarily public, move back to private as soon as we start monitoring the FS
virtual void reload() override;
virtual void reload( const std::string& entryPoint ) override;
virtual void pauseBackgroundOperations() override;
virtual void resumeBackgroundOperations() override;
......
......@@ -73,6 +73,11 @@ void DiscovererWorker::reload()
enqueue( "", true );
}
void DiscovererWorker::reload( const std::string& entryPoint )
{
enqueue( entryPoint, true );
}
void DiscovererWorker::enqueue( const std::string& entryPoint, bool reload )
{
std::unique_lock<std::mutex> lock( m_mutex );
......@@ -131,12 +136,15 @@ void DiscovererWorker::run()
else
{
if ( m_cb != nullptr )
m_cb->onReloadStarted();
m_cb->onReloadStarted( task.entryPoint );
for ( auto& d : m_discoverers )
{
try
{
d->reload();
if ( task.entryPoint.empty() == true )
d->reload();
else
d->reload( task.entryPoint );
}
catch(std::exception& ex)
{
......@@ -146,7 +154,7 @@ void DiscovererWorker::run()
break;
}
if ( m_cb != nullptr )
m_cb->onReloadCompleted();
m_cb->onReloadCompleted( task.entryPoint );
}
}
LOG_INFO( "Exiting DiscovererWorker thread" );
......
......@@ -44,6 +44,7 @@ public:
virtual bool discover( const std::string& entryPoint ) override;
virtual void reload() override;
virtual void reload( const std::string& entryPoint ) override;
private:
void enqueue(const std::string& entryPoint , bool reload);
......
......@@ -70,6 +70,7 @@ bool FsDiscoverer::discover( const std::string &entryPoint )
void FsDiscoverer::reload()
{
LOG_INFO( "Reloading all folders" );
// Start by checking if previously known devices have been plugged/unplugged
checkDevices();
auto rootFolders = Folder::fetchAll( m_dbConn, 0 );
......@@ -87,6 +88,24 @@ void FsDiscoverer::reload()
}
}
void FsDiscoverer::reload( const std::string& entryPoint )
{
LOG_INFO( "Reloading folder ", entryPoint );
auto folder = Folder::fromPath( m_dbConn, entryPoint );
if ( folder == nullptr )
{
LOG_ERROR( "Can't reload ", entryPoint, ": folder wasn't found in database" );
return;
}
auto folderFs = m_fsFactory->createDirectory( folder->path() );
if ( folderFs == nullptr )
{
LOG_ERROR(" Failed to create a fs::IDirectory representing ", folder->path() );
}
auto blist = blacklist();
checkFolder( *folderFs, *folder, blist );
}
void FsDiscoverer::checkDevices()
{
m_fsFactory->refresh();
......
......@@ -37,6 +37,7 @@ public:
FsDiscoverer(std::shared_ptr<factory::IFileSystem> fsFactory, MediaLibrary* ml, DBConnection dbConn );
virtual bool discover(const std::string &entryPoint ) override;
virtual void reload() override;
virtual void reload( const std::string& entryPoint );
private:
///
......
......@@ -51,11 +51,11 @@ public:
m_cond.notify_all();
}
virtual void onReloadStarted() override
virtual void onReloadStarted( const std::string& ) override
{
}
virtual void onReloadCompleted() override
virtual void onReloadCompleted( const std::string& ) override
{
if ( --m_nbReloadExpected == 0 )
m_reloadCond.notify_all();
......
......@@ -25,8 +25,8 @@ private:
void onFileUpdated(MediaPtr) {}
void onDiscoveryStarted(const std::string&) {}
void onDiscoveryCompleted(const std::string&);
void onReloadStarted() {}
void onReloadCompleted() {}
void onReloadStarted( const std::string& ) {}
void onReloadCompleted( const std::string& ) {}
void onParsingStatsUpdated(uint32_t percent);
std::condition_variable m_parsingCompleteVar;
......
......@@ -342,3 +342,26 @@ TEST_F( Folders, InsertNoMediaInRoot )
auto files = ml->files();
ASSERT_EQ( 0u, files.size() );
}
TEST_F( Folders, ReloadSubDir )
{
auto files = ml->files();
ASSERT_EQ( 3u, files.size() );
fsMock->addFile( mock::FileSystemFactory::Root + "newmedia.mkv" );
cbMock->prepareForReload();
ml->reload( mock::FileSystemFactory::SubFolder );
bool reloaded = cbMock->waitForReload();
ASSERT_TRUE( reloaded );
files = ml->files();
ASSERT_EQ( 3u, files.size() );
cbMock->prepareForReload();
ml->reload();
reloaded = cbMock->waitForReload();
ASSERT_TRUE( reloaded );
files = ml->files();
ASSERT_EQ( 4u, files.size() );
}
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