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

File: Fix a potential crash when migrating from 9 to 10

parent 9de1832b
...@@ -108,6 +108,11 @@ const std::string& File::mrl() const ...@@ -108,6 +108,11 @@ const std::string& File::mrl() const
return m_fullPath; return m_fullPath;
} }
const std::string& File::rawMrl() const
{
return m_mrl;
}
void File::setMrl( const std::string& mrl ) void File::setMrl( const std::string& mrl )
{ {
if ( m_mrl == mrl ) if ( m_mrl == mrl )
......
...@@ -54,6 +54,13 @@ public: ...@@ -54,6 +54,13 @@ public:
File( MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, Type type, const std::string& mrl ); File( MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, Type type, const std::string& mrl );
virtual int64_t id() const override; virtual int64_t id() const override;
virtual const std::string& mrl() const override; virtual const std::string& mrl() const override;
/**
* @brief rawMrl returns the raw mrl, ie. the mrl from the mountpoint.
* This is the same as MRL for files on non removable devices.
* This is meant to be used when fiddling with the value stored in database
* during a migration, but shouldn't be used otherwise, as it would be unusable
*/
const std::string& rawMrl() const;
void setMrl( const std::string& mrl ); void setMrl( const std::string& mrl );
virtual Type type() const override; virtual Type type() const override;
virtual unsigned int lastModificationDate() const override; virtual unsigned int lastModificationDate() const override;
......
...@@ -958,8 +958,10 @@ void MediaLibrary::migrateModel9to10() ...@@ -958,8 +958,10 @@ void MediaLibrary::migrateModel9to10()
auto t = getConn()->newTransaction(); auto t = getConn()->newTransaction();
for ( const auto& f : files ) for ( const auto& f : files )
{ {
auto newMrl = utils::url::encode( utils::url::decode( f->mrl() ) ); // We must not call mrl() from here. We might not have all devices yet,
LOG_INFO( "Converting ", f->mrl(), " to ", newMrl ); // and calling mrl would crash for files stored on removable devices.
auto newMrl = utils::url::encode( utils::url::decode( f->rawMrl() ) );
LOG_INFO( "Converting ", f->rawMrl(), " to ", newMrl );
f->setMrl( newMrl ); f->setMrl( newMrl );
} }
t->commit(); t->commit();
......
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