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

Folders: Expose an isRemovable flag

parent f4089d7a
......@@ -15,5 +15,6 @@ public:
virtual std::vector<FolderPtr> folders() = 0;
virtual unsigned int lastModificationDate() = 0;
virtual bool setLastModificationDate( unsigned int lastModificationDate ) = 0;
virtual bool isRemovable() = 0;
virtual FolderPtr parent() = 0;
};
......@@ -28,12 +28,14 @@ Folder::Folder( DBConnection dbConnection, sqlite3_stmt* stmt )
m_path = sqlite::Traits<std::string>::Load( stmt, 1 );
m_parent = sqlite::Traits<unsigned int>::Load( stmt, 2 );
m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 3 );
m_isRemovable = sqlite::Traits<bool>::Load( stmt, 4 );
}
Folder::Folder( const std::string& path, unsigned int parent, unsigned int lastModificationDate )
Folder::Folder( const std::string& path, unsigned int parent, unsigned int lastModificationDate, bool isRemovable )
: m_path( path )
, m_parent( parent )
, m_lastModificationDate( lastModificationDate )
, m_isRemovable( isRemovable )
{
}
......@@ -45,18 +47,19 @@ bool Folder::createTable(DBConnection connection)
"path TEXT UNIQUE ON CONFLICT FAIL,"
"id_parent UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"is_removable INTEGER,"
"FOREIGN KEY (id_parent) REFERENCES " + policy::FolderTable::Name +
"(id_folder) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( connection, req );
}
FolderPtr Folder::create(DBConnection connection, const std::string& path, unsigned int parent, unsigned int lastModifDate )
FolderPtr Folder::create(DBConnection connection, const std::string& path, unsigned int parent, unsigned int lastModifDate, bool isRemovable )
{
auto self = std::make_shared<Folder>( path, parent, lastModifDate );
auto self = std::make_shared<Folder>( path, parent, lastModifDate, isRemovable );
static const std::string req = "INSERT INTO " + policy::FolderTable::Name +
"(path, id_parent, last_modification_date) VALUES(?, ?, ?)";
if ( _Cache::insert( connection, self, req, path, sqlite::ForeignKey( parent ), lastModifDate ) == false )
"(path, id_parent, last_modification_date, is_removable) VALUES(?, ?, ?, ?)";
if ( _Cache::insert( connection, self, req, path, sqlite::ForeignKey( parent ), lastModifDate, isRemovable ) == false )
return nullptr;
self->m_dbConection = connection;
return self;
......@@ -108,3 +111,8 @@ bool Folder::setLastModificationDate( unsigned int lastModificationDate )
m_lastModificationDate = lastModificationDate;
return true;
}
bool Folder::isRemovable()
{
return m_isRemovable;
}
......@@ -31,10 +31,10 @@ class Folder : public IFolder, public Cache<Folder, IFolder, policy::FolderTable
public:
Folder(DBConnection dbConnection, sqlite3_stmt* stmt);
Folder(const std::string& path , unsigned int parent, unsigned int lastModificationDate );
Folder(const std::string& path , unsigned int parent, unsigned int lastModificationDate, bool isRemovable );
static bool createTable( DBConnection connection );
static FolderPtr create(DBConnection connection, const std::string& path , unsigned int parent, unsigned int lastModifDate);
static FolderPtr create(DBConnection connection, const std::string& path , unsigned int parent, unsigned int lastModifDate, bool isRemovable);
virtual unsigned int id() const override;
virtual const std::string& path() override;
......@@ -43,6 +43,7 @@ public:
virtual FolderPtr parent() override;
virtual unsigned int lastModificationDate() override;
virtual bool setLastModificationDate(unsigned int lastModificationDate) override;
virtual bool isRemovable() override;
private:
DBConnection m_dbConection;
......@@ -51,6 +52,7 @@ private:
std::string m_path;
unsigned int m_parent;
unsigned int m_lastModificationDate;
bool m_isRemovable;
friend _Cache;
friend struct policy::FolderTable;
......
......@@ -135,7 +135,7 @@ FolderPtr MediaLibrary::addFolder( const std::string& path )
continue;
}
auto folder = Folder::create( m_dbConnection, dir->path(), currentFolder.second, dir->lastModificationDate() );
auto folder = Folder::create( m_dbConnection, dir->path(), currentFolder.second, dir->lastModificationDate(), dir->isRemovable() );
if ( folder == nullptr && root == nullptr )
return nullptr;
if ( root == nullptr )
......
......@@ -18,5 +18,6 @@ namespace fs
/// Returns a list of absolute path to this folder subdirectories
virtual const std::vector<std::string>& dirs() const = 0;
virtual unsigned int lastModificationDate() const = 0;
virtual bool isRemovable() const = 0;
};
}
......@@ -41,6 +41,12 @@ unsigned int Directory::lastModificationDate() const
return m_lastModificationDate;
}
bool Directory::isRemovable() const
{
//FIXME
return false;
}
std::string Directory::toAbsolute(const std::string& path)
{
auto abs = std::unique_ptr<char[]>( new char[PATH_MAX] );
......
......@@ -14,6 +14,7 @@ public:
virtual const std::vector<std::string>& files() const override;
virtual const std::vector<std::string>& dirs() const override;
virtual unsigned int lastModificationDate() const override;
virtual bool isRemovable() const override;
private:
static std::string toAbsolute( const std::string& path );
......
......@@ -72,6 +72,7 @@ public:
: m_path( path )
, m_parent( parent )
, m_lastModificationDate( lastModif )
, m_isRemovable( false )
{
}
......@@ -139,12 +140,23 @@ public:
m_lastModificationDate++;
}
virtual bool isRemovable() const override
{
return m_isRemovable;
}
void markRemovable()
{
m_isRemovable = true;
}
private:
std::string m_path;
std::vector<std::string> m_files;
std::vector<std::string> m_dirs;
std::shared_ptr<mock::Directory> m_parent;
unsigned int m_lastModificationDate;
bool m_isRemovable;
};
......@@ -482,3 +494,20 @@ TEST_F( Folders, UpdateFile )
// id should have changed
ASSERT_NE( id, f->id() );
}
// This simply tests that the flag is properly stored in db
TEST_F( Folders, CheckRemovable )
{
fsMock->dirs[mock::FileSystemFactory::SubFolder]->markRemovable();
auto f = ml->addFolder( "." );
ASSERT_FALSE( f->isRemovable() );
auto subfolder = ml->folder( mock::FileSystemFactory::SubFolder );
ASSERT_TRUE( subfolder->isRemovable() );
Reload();
f = ml->folder( mock::FileSystemFactory::Root );
ASSERT_FALSE( f->isRemovable() );
subfolder = ml->folder( mock::FileSystemFactory::SubFolder );
ASSERT_TRUE( subfolder->isRemovable() );
}
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