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

MediaLibrary: Fix fetching external media

This was working by accident due to the mock fsfactory pretending to
support all path
parent ac067a47
......@@ -266,7 +266,7 @@ std::shared_ptr<File> File::create( MediaLibraryPtr ml, int64_t mediaId, IFile::
std::shared_ptr<File> File::fromPath( MediaLibraryPtr ml, const std::string& path )
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name + " WHERE mrl = ?";
static const std::string req = "SELECT * FROM " + policy::FileTable::Name + " WHERE mrl = ? AND folder_id IS NOT NULL";
auto file = fetch( ml, req, path );
if ( file == nullptr )
return nullptr;
......@@ -288,4 +288,15 @@ std::shared_ptr<File> File::fromFileName( MediaLibraryPtr ml, const std::string&
return file;
}
std::shared_ptr<File> File::fromMrl( MediaLibraryPtr ml, const std::string& mrl )
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name + " WHERE mrl = ? "
"AND folder_id IS NULL";
auto file = fetch( ml, req, mrl );
if ( file == nullptr )
return nullptr;
assert( file->m_isExternal == true );
return file;
}
}
......@@ -102,6 +102,15 @@ public:
*/
static std::shared_ptr<File> fromFileName( MediaLibraryPtr ml, const std::string& fileName, int64_t folderId );
/**
* @brief fromMrl Attempts to find an external stream (ie. it was added with MediaLibrary::addMedia,
* and not discovered through any IDiscoverer)
* This implies the folder_id is null
* @return
*/
static std::shared_ptr<File> fromMrl( MediaLibraryPtr ml, const std::string& mrl );
private:
MediaLibraryPtr m_ml;
......
......@@ -266,7 +266,16 @@ MediaPtr MediaLibrary::media( const std::string& mrl ) const
{
auto fsFactory = fsFactoryForPath( mrl );
if ( fsFactory == nullptr )
return nullptr;
{
// Assume this is an external media with a null folder_id
auto file = File::fromMrl( this, mrl );
if ( file == nullptr )
{
LOG_WARN( "Failed to fetch stream representation for ", mrl );
return nullptr;
}
return file->media();
}
auto device = fsFactory->createDeviceFromPath( mrl );
if ( device == nullptr )
{
......
......@@ -354,9 +354,12 @@ public:
return false;
}
virtual bool isPathSupported( const std::string& ) const override
virtual bool isPathSupported( const std::string& mrl ) const override
{
return true;
auto it = mrl.find( "://" );
if ( it == std::string::npos )
return true;
return mrl.compare( 0, 7, "file://" ) == 0;
}
virtual bool isNetworkFileSystem() const override
......
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