Commit 45757478 authored by Alexandre Fernandez's avatar Alexandre Fernandez

Folder: Add a table containing root points to ignore

parent 5e7c547e
......@@ -87,6 +87,12 @@ bool Folder::createTable( sqlite::Connection* connection)
"(id_device) ON DELETE CASCADE,"
"UNIQUE(path, device_id) ON CONFLICT FAIL"
")";
std::string exclEntryReq = "CREATE TABLE IF NOT EXISTS ExcludedEntryFolder("
"folder_id UNSIGNED INTEGER NOT NULL,"
"FOREIGN KEY (folder_id) REFERENCES " + policy::FolderTable::Name +
"(id_folder) ON DELETE CASCADE,"
"UNIQUE(folder_id) ON CONFLICT FAIL"
")";
std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_device_present AFTER UPDATE OF is_present ON "
+ policy::DeviceTable::Name +
" BEGIN"
......@@ -97,6 +103,7 @@ bool Folder::createTable( sqlite::Connection* connection)
std::string parentFolderIndexReq = "CREATE INDEX IF NOT EXISTS parent_folder_id_idx ON " +
policy::FolderTable::Name + " (parent_id)";
return sqlite::Tools::executeRequest( connection, req ) &&
sqlite::Tools::executeRequest( connection, exclEntryReq ) &&
sqlite::Tools::executeRequest( connection, triggerReq ) &&
sqlite::Tools::executeRequest( connection, deviceIndexReq ) &&
sqlite::Tools::executeRequest( connection, parentFolderIndexReq );
......@@ -123,6 +130,12 @@ std::shared_ptr<Folder> Folder::create( MediaLibraryPtr ml, const std::string& m
return self;
}
void Folder::excludeEntryFolder( MediaLibraryPtr ml, int64_t folderId )
{
std::string req = "INSERT INTO ExcludedEntryFolder(folder_id) VALUES(?)";
sqlite::Tools::executeRequest( ml->getConn(), req, folderId );
}
bool Folder::blacklist( MediaLibraryPtr ml, const std::string& mrl )
{
// Ensure we delete the existing folder if any & blacklist the folder in an "atomic" way
......@@ -307,8 +320,11 @@ bool Folder::isRootFolder() const
std::vector<std::shared_ptr<Folder>> Folder::fetchRootFolders( MediaLibraryPtr ml )
{
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name
+ " WHERE parent_id IS NULL AND is_blacklisted = 0 AND is_present = 1";
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name +
" LEFT JOIN ExcludedEntryFolder"
" ON " + policy::FolderTable::Name + ".id_folder = ExcludedEntryFolder.folder_id"
" WHERE ExcludedEntryFolder.folder_id IS NULL AND"
" parent_id IS NULL AND is_blacklisted = 0 AND is_present = 1";
return DatabaseHelpers::fetchAll<Folder>( ml, req );
}
......
......@@ -62,6 +62,7 @@ public:
static bool createTable( sqlite::Connection* connection );
static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& mrl, int64_t parentId, Device& device, fs::IDevice& deviceFs );
static void excludeEntryFolder( MediaLibraryPtr ml, int64_t folderId );
static bool blacklist( MediaLibraryPtr ml, const std::string& mrl );
static std::vector<std::shared_ptr<Folder>> fetchRootFolders( MediaLibraryPtr ml );
......
......@@ -320,6 +320,9 @@ void MetadataParser::addPlaylistElement( parser::Task& task, const std::shared_p
if ( parentKnown == false )
{
discoverer.discover( entryPoint );
auto entryFolder = Folder::fromMrl( m_ml, entryPoint );
if ( entryFolder != nullptr )
Folder::excludeEntryFolder( m_ml, entryFolder->id() );
return;
}
discoverer.reload( directoryMrl );
......
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