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

MediaLibrary: addFile: Expect a fs::IFile instead of a path

parent 8e9656c4
......@@ -201,21 +201,10 @@ std::vector<MediaPtr> MediaLibrary::videoFiles()
return Media::fetchAll<IMedia>( m_dbConnection.get(), req, IMedia::Type::VideoType );
}
std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder& parentFolder, fs::IDirectory& parentFolderFs )
std::shared_ptr<Media> MediaLibrary::addFile( const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs )
{
std::shared_ptr<fs::IFile> fileFs;
try
{
fileFs = m_fsFactory->createFile( path );
}
catch (std::exception& ex)
{
LOG_ERROR( "Failed to create an IFile for ", path, ": ", ex.what() );
return nullptr;
}
auto type = IMedia::Type::UnknownType;
auto ext = fileFs->extension();
auto ext = fileFs.extension();
auto predicate = [ext](const std::string& v) {
return strcasecmp(v.c_str(), ext.c_str()) == 0;
};
......@@ -233,18 +222,18 @@ std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder& p
if ( type == IMedia::Type::UnknownType )
return nullptr;
LOG_INFO( "Adding ", path );
auto mptr = Media::create( m_dbConnection.get(), type, *fileFs );
LOG_INFO( "Adding ", fileFs.fullPath() );
auto mptr = Media::create( m_dbConnection.get(), type, fileFs );
if ( mptr == nullptr )
{
LOG_ERROR( "Failed to add media ", fileFs->fullPath(), " to the media library" );
LOG_ERROR( "Failed to add media ", fileFs.fullPath(), " to the media library" );
return nullptr;
}
// For now, assume all media are made of a single file
auto file = mptr->addFile( *fileFs, parentFolder, parentFolderFs, File::Type::Entire );
auto file = mptr->addFile( fileFs, parentFolder, parentFolderFs, File::Type::Entire );
if ( file == nullptr )
{
LOG_ERROR( "Failed to add file ", fileFs->fullPath(), " to media #", mptr->id() );
LOG_ERROR( "Failed to add file ", fileFs.fullPath(), " to media #", mptr->id() );
Media::destroy( m_dbConnection.get(), mptr->id() );
return nullptr;
}
......
......@@ -59,7 +59,7 @@ class MediaLibrary : public IMediaLibrary
std::vector<MediaPtr> files();
virtual std::vector<MediaPtr> audioFiles() override;
virtual std::vector<MediaPtr> videoFiles() override;
std::shared_ptr<Media> addFile( const std::string& path, Folder& parentFolder, fs::IDirectory& parentFolderFs );
std::shared_ptr<Media> addFile( const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs );
bool deleteFolder(const Folder& folder );
std::shared_ptr<Device> device( const std::string& uuid );
......
......@@ -222,7 +222,7 @@ void FsDiscoverer::checkFiles( fs::IDirectory& parentFolderFs, Folder& parentFol
f->media()->removeFile( *f );
// Insert all files at once to avoid SQL write contention
for ( auto& p : filesToAdd )
m_ml->addFile( p->fullPath(), parentFolder, parentFolderFs );
m_ml->addFile( *p, parentFolder, parentFolderFs );
t->commit();
LOG_INFO( "Done checking files in ", parentFolderFs.path() );
}
......
......@@ -121,7 +121,8 @@ std::shared_ptr<Folder> MediaLibraryTester::folder( const std::string& path )
std::shared_ptr<Media> MediaLibraryTester::addFile( const std::string& path )
{
return MediaLibrary::addFile( path, dummyFolder, *dummyDirectory );
mock::NoopFile file( path );
return MediaLibrary::addFile( file, dummyFolder, *dummyDirectory );
}
std::shared_ptr<Playlist> MediaLibraryTester::playlist(unsigned int playlistId)
......
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