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

Folder: Remove lastModificationDate

This is not portable, and doesn't work with subfolders, nor with
mountpoints.
parent c26c6f4a
......@@ -46,22 +46,19 @@ Folder::Folder( DBConnection dbConnection, sqlite::Row& row )
row >> m_id
>> m_path
>> m_parent
>> m_lastModificationDate
>> m_isBlacklisted
>> m_deviceId
>> m_isPresent;
}
Folder::Folder( const std::string& path, time_t lastModificationDate, unsigned int parent, unsigned int deviceId )
Folder::Folder( const std::string& path, unsigned int parent, unsigned int deviceId )
: m_id( 0 )
, m_path( path )
, m_parent( parent )
, m_lastModificationDate( lastModificationDate )
, m_isBlacklisted( false )
, m_deviceId( deviceId )
, m_isPresent( true )
{
// Don't fetch the device mountpoint from here, we don't have a DBConnection yet.
}
bool Folder::createTable(DBConnection connection)
......@@ -71,7 +68,6 @@ bool Folder::createTable(DBConnection connection)
"id_folder INTEGER PRIMARY KEY AUTOINCREMENT,"
"path TEXT,"
"id_parent UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"is_blacklisted INTEGER,"
"device_id UNSIGNED INTEGER,"
"is_present BOOLEAN NOT NULL DEFAULT 1,"
......@@ -89,14 +85,13 @@ bool Folder::createTable(DBConnection connection)
sqlite::Tools::executeRequest( connection, triggerReq );
}
std::shared_ptr<Folder> Folder::create( DBConnection connection, const std::string& fullPath, time_t lastModificationDate, unsigned int parentId, Device& device, fs::IDevice& deviceFs )
std::shared_ptr<Folder> Folder::create( DBConnection connection, const std::string& fullPath, unsigned int parentId, Device& device, fs::IDevice& deviceFs )
{
auto path = utils::file::removePath( fullPath, deviceFs.mountpoint() );
auto self = std::make_shared<Folder>( path, lastModificationDate, parentId, device.id() );
auto self = std::make_shared<Folder>( path, parentId, device.id() );
static const std::string req = "INSERT INTO " + policy::FolderTable::Name +
"(path, id_parent, last_modification_date, device_id) VALUES(?, ?, ?, ?)";
if ( insert( connection, self, req, path, sqlite::ForeignKey( parentId ),
lastModificationDate, device.id() ) == false )
"(path, id_parent, device_id) VALUES(?, ?, ?)";
if ( insert( connection, self, req, path, sqlite::ForeignKey( parentId ), device.id() ) == false )
return nullptr;
self->m_dbConection = connection;
self->m_deviceMountpoint = deviceFs.mountpoint();
......@@ -185,21 +180,6 @@ std::shared_ptr<Folder> Folder::parent()
return fetch( m_dbConection, m_parent );
}
unsigned int Folder::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;
}
unsigned int Folder::deviceId() const
{
return m_deviceId;
......
......@@ -54,10 +54,10 @@ class Folder : public DatabaseHelpers<Folder, policy::FolderTable>
{
public:
Folder( DBConnection dbConnection, sqlite::Row& row );
Folder(const std::string& path, time_t lastModificationDate, unsigned int parent , unsigned int deviceId);
Folder( const std::string& path, unsigned int parent , unsigned int deviceId );
static bool createTable( DBConnection connection );
static std::shared_ptr<Folder> create(DBConnection connection, const std::string& path, time_t lastModificationDate, unsigned int parentId, Device& device , fs::IDevice& deviceFs);
static std::shared_ptr<Folder> create( DBConnection connection, const std::string& path, unsigned int parentId, Device& device, fs::IDevice& deviceFs );
static bool blacklist(DBConnection connection, const std::string& fullPath );
static std::vector<std::shared_ptr<Folder>> fetchAll( DBConnection dbConn, unsigned int parentFolderId );
///
......@@ -74,8 +74,6 @@ public:
std::vector<MediaPtr> files();
std::vector<std::shared_ptr<Folder>> folders();
std::shared_ptr<Folder> parent();
unsigned int lastModificationDate();
bool setLastModificationDate(unsigned int lastModificationDate);
unsigned int deviceId() const;
bool isPresent() const;
......@@ -89,7 +87,6 @@ private:
// This contains the path relative to the device mountpoint (ie. excluding it)
std::string m_path;
unsigned int m_parent;
unsigned int m_lastModificationDate;
bool m_isBlacklisted;
unsigned int m_deviceId;
bool m_isPresent;
......
......@@ -84,14 +84,8 @@ void FsDiscoverer::reload()
m_ml->deleteFolder( f.get() );
continue;
}
if ( folder->lastModificationDate() == f->lastModificationDate() )
{
LOG_INFO( f->path(), " isn't modified" );
continue;
}
checkSubfolders( folder.get(), f.get(), blist );
checkFiles( folder.get(), f.get() );
f->setLastModificationDate( folder->lastModificationDate() );
}
}
......@@ -142,17 +136,11 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, Folder* parentFolder
continue;
}
auto folderInDb = *it;
if ( subFolder->lastModificationDate() == folderInDb->lastModificationDate() )
{
subFoldersInDB.erase( it );
continue;
}
// In any case, check for modifications, as a change related to a mountpoint might
// not update the folder modification date.
// Also, relying on the modification date probably isn't portable
checkSubfolders( subFolder.get(), folderInDb.get(), blacklist );
checkFiles( subFolder.get(), folderInDb.get() );
folderInDb->setLastModificationDate( subFolder->lastModificationDate() );
subFoldersInDB.erase( it );
}
// Now all folders we had in DB but haven't seen from the FS must have been deleted.
......@@ -224,8 +212,6 @@ bool FsDiscoverer::isBlacklisted( const fs::IDirectory& directory, const std::ve
bool FsDiscoverer::addFolder( fs::IDirectory* folder, Folder* parentFolder, const std::vector<std::shared_ptr<Folder>>& blacklist ) const
{
// Force <0> as lastModificationDate, so this folder is detected as outdated
// by the modification checking code
auto deviceFs = folder->device();
// We are creating a folder, there has to be a device containing it.
assert( deviceFs != nullptr );
......@@ -236,13 +222,12 @@ bool FsDiscoverer::addFolder( fs::IDirectory* folder, Folder* parentFolder, cons
device = Device::create( m_dbConn, deviceFs->uuid(), deviceFs->isRemovable() );
}
auto f = Folder::create( m_dbConn, folder->path(), 0,
parentFolder != nullptr ? parentFolder->id() : 0, *device, *deviceFs );
auto f = Folder::create( m_dbConn, folder->path(), parentFolder != nullptr ? parentFolder->id() : 0,
*device, *deviceFs );
if ( f == nullptr )
return false;
checkFiles( folder, f.get() );
checkSubfolders( folder, f.get(), blacklist );
f->setLastModificationDate( folder->lastModificationDate() );
return true;
}
......@@ -191,26 +191,6 @@ TEST_F( Folders, ListFolders )
ASSERT_EQ( mock::FileSystemFactory::SubFolder + "subfile.mp4", file->mrl() );
}
TEST_F( Folders, LastModificationDate )
{
cbMock->prepareForWait( 1 );
ml->discover( mock::FileSystemFactory::Root );
bool discovered = cbMock->wait();
ASSERT_TRUE( discovered );
auto f = ml->folder( mock::FileSystemFactory::Root );
ASSERT_NE( 0u, f->lastModificationDate() );
auto subFolders = f->folders();
ASSERT_NE( 0u, subFolders[0]->lastModificationDate() );
Reload();
f = ml->folder( f->path() );
ASSERT_NE( 0u, f->lastModificationDate() );
subFolders = f->folders();
ASSERT_NE( 0u, subFolders[0]->lastModificationDate() );
}
TEST_F( Folders, NewFolderWithFile )
{
cbMock->prepareForWait( 1 );
......@@ -248,7 +228,6 @@ TEST_F( Folders, NewFileInSubFolder )
ASSERT_EQ( 3u, ml->files().size() );
f = ml->folder( mock::FileSystemFactory::SubFolder );
auto lmd = f->lastModificationDate();
// Do not watch for live changes
ml.reset();
fsMock->addFile( mock::FileSystemFactory::SubFolder + "newfile.avi" );
......@@ -264,7 +243,6 @@ TEST_F( Folders, NewFileInSubFolder )
ASSERT_EQ( 2u, f->files().size() );
ASSERT_NE( nullptr, file );
ASSERT_FALSE( std::static_pointer_cast<Media>( file )->isStandAlone() );
ASSERT_NE( lmd, f->lastModificationDate() );
}
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