Commit 9ddc11ef authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by Hugo Beauzée-Luyssen

MediaLibrary: Refresh all devices from the discoverer thread

Instead of doing it during the initialization.
This now also handles network devices, which shouldn't be refreshed from
the main thread (or any other thread that's not a background
medialibrary thread, as the network device refresh may block for a few
seconds)
This reverts 7502a15b
parent bd2445f5
......@@ -434,48 +434,6 @@ InitializeResult MediaLibrary::initialize( const std::string& dbPath,
return InitializeResult::Failed;
}
// Don't run device refresh if the database is in a corrupted state
// We expect the user to recreate it, so devices will be added when they
// are first required during the discovery step.
if ( res == InitializeResult::Success )
{
try
{
// Now that we have initialized the database connection and migrated
// the model if needed, we can try to flush old devices.
// This only concerns local fs factories, as the network ones are
// not started yet, and do not have a device list available
for ( auto& fsFactory : m_fsFactories )
{
assert( fsFactory->isNetworkFileSystem() == false );
refreshDevices( *fsFactory );
}
// Now that we know which devices are plugged, check for outdated devices
removeOldEntities( this );
}
catch ( const sqlite::errors::DatabaseCorrupt& )
{
LOG_ERROR( "SQLite reported the database as corrupted" );
res = InitializeResult::DbCorrupted;
}
catch ( const sqlite::errors::GenericError& )
{
// This should only happen when the request is invalid, but can happen
// in case a migration fails, and we end up referencing a field that
// doesn't exist.
// Report it for release builds, but fail hard otherwise
assert( false );
return InitializeResult::DbCorrupted;
}
// Handle every other errors as a critical failure
catch ( const sqlite::errors::Exception& ex )
{
LOG_ERROR( "An SQLite error occurred: ", ex.what() );
return InitializeResult::Failed;
}
}
m_initialized = true;
LOG_INFO( "Successfully initialized" );
return res;
......@@ -958,6 +916,7 @@ void MediaLibrary::startDiscoverer()
m_discovererWorker->addDiscoverer( std::unique_ptr<IDiscoverer>( new FsDiscoverer( fsFactory, this, m_callback,
std::move ( probePtr ) ) ) );
}
m_discovererWorker->reloadAllDevices();
}
void MediaLibrary::startDeletionNotifier()
......
......@@ -99,9 +99,8 @@ TEST_F( DeviceEntity, Create )
ASSERT_NE( nullptr, d );
ASSERT_EQ( "dummy", d->uuid() );
ASSERT_TRUE( d->isRemovable() );
// Since there is no FsFactory to testify that this device is still plugged, the reload
// will mark it as "absent"
ASSERT_FALSE( d->isPresent() );
// The device won't be marked absent until the discoverer starts, but it won't
// happen in unit case configuration
}
TEST_F( DeviceEntity, SetPresent )
......
......@@ -941,7 +941,7 @@ TEST_F( Medias, VacuumOldExternal )
ml->outdateAllExternalMedia();
Reload();
MediaLibrary::removeOldEntities( ml.get() );
m1 = ml->media( m1->id() );
m2 = ml->media( m2->id() );
......@@ -964,7 +964,7 @@ TEST_F( Medias, VacuumNeverPlayedMedia )
ml->setMediaInsertionDate( m1->id(), 1 );
Reload();
MediaLibrary::removeOldEntities( ml.get() );
m1 = ml->media( m1->id() );
m2 = ml->media( m2->id() );
......
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