Commit f107a611 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Update last modification date when a change is found and acted upon

parent 3cced5ad
...@@ -14,5 +14,6 @@ public: ...@@ -14,5 +14,6 @@ public:
virtual std::vector<FilePtr> files() = 0; virtual std::vector<FilePtr> files() = 0;
virtual std::vector<FolderPtr> folders() = 0; virtual std::vector<FolderPtr> folders() = 0;
virtual unsigned int lastModificationDate() = 0; virtual unsigned int lastModificationDate() = 0;
virtual bool setLastModificationDate( unsigned int lastModificationDate ) = 0;
virtual FolderPtr parent() = 0; virtual FolderPtr parent() = 0;
}; };
...@@ -98,3 +98,13 @@ unsigned int Folder::lastModificationDate() ...@@ -98,3 +98,13 @@ unsigned int Folder::lastModificationDate()
{ {
return m_lastModificationDate; return m_lastModificationDate;
} }
bool Folder::setLastModificationDate( unsigned int lastModificationDate )
{
static const std::string req = "UPDATE " + policy::FolderTable::Name +
" SET last_modification_date = ? WHERE id_folder = ?";
if ( sqlite::Tools::executeUpdate( m_dbConection, req, lastModificationDate, m_id ) == false )
return false;
m_lastModificationDate = lastModificationDate;
return true;
}
...@@ -42,6 +42,7 @@ public: ...@@ -42,6 +42,7 @@ public:
virtual std::vector<FolderPtr> folders() override; virtual std::vector<FolderPtr> folders() override;
virtual FolderPtr parent() override; virtual FolderPtr parent() override;
virtual unsigned int lastModificationDate() override; virtual unsigned int lastModificationDate() override;
virtual bool setLastModificationDate(unsigned int lastModificationDate) override;
private: private:
DBConnection m_dbConection; DBConnection m_dbConection;
......
...@@ -257,6 +257,7 @@ bool MediaLibrary::loadFolders() ...@@ -257,6 +257,7 @@ bool MediaLibrary::loadFolders()
} }
std::cout << "... changes detected" << std::endl; std::cout << "... changes detected" << std::endl;
checkSubfolders( folder.get(), f->id() ); checkSubfolders( folder.get(), f->id() );
f->setLastModificationDate( folder->lastModificationDate() );
} }
return true; return true;
} }
...@@ -302,6 +303,7 @@ bool MediaLibrary::checkSubfolders( fs::IDirectory* folder, unsigned int parentI ...@@ -302,6 +303,7 @@ bool MediaLibrary::checkSubfolders( fs::IDirectory* folder, unsigned int parentI
// This folder was modified, let's recurse // This folder was modified, let's recurse
checkSubfolders( subFolder.get(), (*it)->id() ); checkSubfolders( subFolder.get(), (*it)->id() );
checkFiles( subFolder.get(), (*it)->id() ); checkFiles( subFolder.get(), (*it)->id() );
(*it)->setLastModificationDate( subFolder->lastModificationDate() );
subFoldersInDB.erase( it ); subFoldersInDB.erase( it );
} }
// Now all folders we had in DB but haven't seen from the FS must have been deleted. // Now all folders we had in DB but haven't seen from the FS must have been deleted.
......
...@@ -403,9 +403,11 @@ TEST_F( Folders, NewFolderWithFile ) ...@@ -403,9 +403,11 @@ TEST_F( Folders, NewFolderWithFile )
TEST_F( Folders, NewFileInSubFolder ) TEST_F( Folders, NewFileInSubFolder )
{ {
ml->addFolder( "." ); auto f = ml->addFolder( "." );
ASSERT_EQ( 3u, ml->files().size() ); ASSERT_EQ( 3u, ml->files().size() );
f = ml->folder( mock::FileSystemFactory::SubFolder );
auto lmd = f->lastModificationDate();
// Do not watch for live changes // Do not watch for live changes
ml.reset(); ml.reset();
fsMock->addFile( mock::FileSystemFactory::SubFolder, "newfile.avi" ); fsMock->addFile( mock::FileSystemFactory::SubFolder, "newfile.avi" );
...@@ -414,10 +416,11 @@ TEST_F( Folders, NewFileInSubFolder ) ...@@ -414,10 +416,11 @@ TEST_F( Folders, NewFileInSubFolder )
ASSERT_EQ( 4u, ml->files().size() ); ASSERT_EQ( 4u, ml->files().size() );
auto file = ml->file( std::string( mock::FileSystemFactory::SubFolder ) + "newfile.avi" ); auto file = ml->file( std::string( mock::FileSystemFactory::SubFolder ) + "newfile.avi" );
auto f = ml->folder( mock::FileSystemFactory::SubFolder ); f = ml->folder( mock::FileSystemFactory::SubFolder );
ASSERT_EQ( 2u, f->files().size() ); ASSERT_EQ( 2u, f->files().size() );
ASSERT_NE( nullptr, file ); ASSERT_NE( nullptr, file );
ASSERT_FALSE( file->isStandAlone() ); ASSERT_FALSE( file->isStandAlone() );
ASSERT_NE( lmd, f->lastModificationDate() );
} }
TEST_F( Folders, RemoveFileFromDirectory ) TEST_F( Folders, RemoveFileFromDirectory )
......
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