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

Disallow deleting media from its path.

Only use a Media instance & expose media deletion methods internally
only
parent 3287620b
...@@ -97,8 +97,6 @@ class IMediaLibrary ...@@ -97,8 +97,6 @@ class IMediaLibrary
/// \return The newly created file, or nullptr in case of error /// \return The newly created file, or nullptr in case of error
/// ///
virtual MediaPtr file( const std::string& path ) = 0; virtual MediaPtr file( const std::string& path ) = 0;
virtual bool deleteFile( const std::string& mrl ) = 0;
virtual bool deleteFile( MediaPtr file ) = 0;
/// Adds a folder and all the files it contains /// Adds a folder and all the files it contains
virtual FolderPtr folder( const std::string& path ) = 0; virtual FolderPtr folder( const std::string& path ) = 0;
......
...@@ -243,14 +243,9 @@ FolderPtr MediaLibrary::folder( const std::string& path ) ...@@ -243,14 +243,9 @@ FolderPtr MediaLibrary::folder( const std::string& path )
return Folder::fetch( m_dbConnection.get(), path ); return Folder::fetch( m_dbConnection.get(), path );
} }
bool MediaLibrary::deleteFile( const std::string& mrl ) bool MediaLibrary::deleteFile( const Media* file )
{ {
return Media::destroy( m_dbConnection.get(), mrl ); return Media::destroy( m_dbConnection.get(), file );
}
bool MediaLibrary::deleteFile( MediaPtr file )
{
return Media::destroy( m_dbConnection.get(), file.get() );
} }
bool MediaLibrary::deleteFolder( FolderPtr folder ) bool MediaLibrary::deleteFolder( FolderPtr folder )
......
...@@ -52,8 +52,7 @@ class MediaLibrary : public IMediaLibrary ...@@ -52,8 +52,7 @@ class MediaLibrary : public IMediaLibrary
virtual std::vector<MediaPtr> videoFiles() override; virtual std::vector<MediaPtr> videoFiles() override;
virtual MediaPtr file( const std::string& path ) override; virtual MediaPtr file( const std::string& path ) override;
std::shared_ptr<Media> addFile(const std::string& path , FolderPtr parentFolder); std::shared_ptr<Media> addFile(const std::string& path , FolderPtr parentFolder);
virtual bool deleteFile( const std::string& mrl ) override; virtual bool deleteFile(const Media* file );
virtual bool deleteFile( MediaPtr file ) override;
virtual FolderPtr folder( const std::string& path ) override; virtual FolderPtr folder( const std::string& path ) override;
virtual bool deleteFolder( FolderPtr folder ) override; virtual bool deleteFolder( FolderPtr folder ) override;
......
...@@ -174,13 +174,13 @@ void FsDiscoverer::checkFiles( fs::IDirectory* folder, FolderPtr parentFolder ) ...@@ -174,13 +174,13 @@ void FsDiscoverer::checkFiles( fs::IDirectory* folder, FolderPtr parentFolder )
continue; continue;
} }
LOG_INFO( "Forcing file refresh ", filePath ); LOG_INFO( "Forcing file refresh ", filePath );
m_ml->deleteFile( filePath ); m_ml->deleteFile( (*it).get() );
m_ml->addFile( filePath, parentFolder ); m_ml->addFile( filePath, parentFolder );
files.erase( it ); files.erase( it );
} }
for ( auto file : files ) for ( auto file : files )
{ {
LOG_INFO( "File ", file->mrl(), " not found on filesystem, deleting it" ); LOG_INFO( "File ", file->mrl(), " not found on filesystem, deleting it" );
m_ml->deleteFile( file ); m_ml->deleteFile( file.get() );
} }
} }
...@@ -77,7 +77,7 @@ TEST_F( Medias, Delete ) ...@@ -77,7 +77,7 @@ TEST_F( Medias, Delete )
ASSERT_EQ( f, f2 ); ASSERT_EQ( f, f2 );
ml->deleteFile( f ); ml->deleteFile( f.get() );
f2 = ml->file( "media.avi" ); f2 = ml->file( "media.avi" );
ASSERT_EQ( f2, nullptr ); ASSERT_EQ( f2, nullptr );
} }
......
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