Commit 1de02d82 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Remove use of the term blacklist

parent c5bd641e
......@@ -49,7 +49,7 @@ Folder::Folder( MediaLibraryPtr ml, sqlite::Row& row )
, m_id( row.load<decltype(m_id)>( 0 ) )
, m_path( row.load<decltype(m_path)>( 1 ) )
, m_parent( row.load<decltype(m_parent)>( 2 ) )
, m_isBlacklisted( row.load<decltype(m_isBlacklisted)>( 3 ) )
, m_isBanned( row.load<decltype(m_isBanned)>( 3 ) )
, m_deviceId( row.load<decltype(m_deviceId)>( 4 ) )
, m_isRemovable( row.load<decltype(m_isRemovable)>( 5 ) )
{
......@@ -60,7 +60,7 @@ Folder::Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent, int6
, m_id( 0 )
, m_path( path )
, m_parent( parent )
, m_isBlacklisted( false )
, m_isBanned( false )
, m_deviceId( deviceId )
, m_isRemovable( isRemovable )
{
......@@ -111,17 +111,17 @@ void Folder::excludeEntryFolder( MediaLibraryPtr ml, int64_t folderId )
sqlite::Tools::executeRequest( ml->getConn(), req, folderId );
}
bool Folder::blacklist( MediaLibraryPtr ml, const std::string& mrl )
bool Folder::ban( MediaLibraryPtr ml, const std::string& mrl )
{
// Ensure we delete the existing folder if any & blacklist the folder in an "atomic" way
// Ensure we delete the existing folder if any & ban the folder in an "atomic" way
return sqlite::Tools::withRetries( 3, [ml, &mrl]() {
auto t = ml->getConn()->newTransaction();
auto f = fromMrl( ml, mrl, BannedType::Any );
if ( f != nullptr )
{
// No need to blacklist a folder twice
if ( f->m_isBlacklisted == true )
// No need to ban a folder twice
if ( f->m_isBanned == true )
return true;
// Let the foreign key destroy everything beneath this folder
destroy( ml, f->id() );
......@@ -154,7 +154,7 @@ bool Folder::blacklist( MediaLibraryPtr ml, const std::string& mrl )
else
path = mrl;
static const std::string req = "INSERT INTO " + Folder::Table::Name +
"(path, parent_id, is_blacklisted, device_id, is_removable) VALUES(?, ?, ?, ?, ?)";
"(path, parent_id, is_banned, device_id, is_removable) VALUES(?, ?, ?, ?, ?)";
auto res = sqlite::Tools::executeInsert( ml->getConn(), req, path, nullptr, true, device->id(), deviceFs->isRemovable() ) != 0;
t->commit();
return res;
......@@ -166,7 +166,7 @@ std::shared_ptr<Folder> Folder::fromMrl( MediaLibraryPtr ml, const std::string&
return fromMrl( ml, mrl, BannedType::No );
}
std::shared_ptr<Folder> Folder::blacklistedFolder( MediaLibraryPtr ml, const std::string& mrl )
std::shared_ptr<Folder> Folder::bannedFolder( MediaLibraryPtr ml, const std::string& mrl )
{
return fromMrl( ml, mrl, BannedType::Yes );
}
......@@ -200,7 +200,7 @@ std::shared_ptr<Folder> Folder::fromMrl( MediaLibraryPtr ml, const std::string&
std::string req = "SELECT * FROM " + Folder::Table::Name + " WHERE path = ? AND is_removable = 0";
if ( bannedType == BannedType::Any )
return fetch( ml, req, folderFs->mrl() );
req += " AND is_blacklisted = ?";
req += " AND is_banned = ?";
return fetch( ml, req, folderFs->mrl(), bannedType == BannedType::Yes ? true : false );
}
......@@ -217,7 +217,7 @@ std::shared_ptr<Folder> Folder::fromMrl( MediaLibraryPtr ml, const std::string&
}
else
{
req += " AND is_blacklisted = ?";
req += " AND is_banned = ?";
folder = fetch( ml, req, path, device->id(), bannedType == BannedType::Yes ? true : false );
}
if ( folder == nullptr )
......@@ -298,7 +298,7 @@ std::vector<std::shared_ptr<Folder>> Folder::folders()
{
static const std::string req = "SELECT * FROM " + Folder::Table::Name + " f "
" LEFT JOIN " + Device::Table::Name + " d ON d.id_device = f.device_id"
" WHERE parent_id = ? AND is_blacklisted = 0 AND d.is_present != 0";
" WHERE parent_id = ? AND is_banned = 0 AND d.is_present != 0";
return DatabaseHelpers::fetchAll<Folder>( m_ml, req, m_id );
}
......@@ -328,7 +328,7 @@ bool Folder::isPresent() const
bool Folder::isBanned() const
{
return m_isBlacklisted;
return m_isBanned;
}
bool Folder::isRootFolder() const
......@@ -343,7 +343,7 @@ std::vector<std::shared_ptr<Folder>> Folder::fetchRootFolders( MediaLibraryPtr m
" ON f.id_folder = ExcludedEntryFolder.folder_id"
" LEFT JOIN " + Device::Table::Name + " d ON d.id_device = f.device_id"
" WHERE ExcludedEntryFolder.folder_id IS NULL AND"
" parent_id IS NULL AND is_blacklisted = 0 AND d.is_present != 0";
" parent_id IS NULL AND is_banned = 0 AND d.is_present != 0";
return DatabaseHelpers::fetchAll<Folder>( ml, req );
}
......
......@@ -60,11 +60,11 @@ public:
static void createTriggers( 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 bool ban( MediaLibraryPtr ml, const std::string& mrl );
static std::vector<std::shared_ptr<Folder>> fetchRootFolders( MediaLibraryPtr ml );
static std::shared_ptr<Folder> fromMrl(MediaLibraryPtr ml, const std::string& mrl );
static std::shared_ptr<Folder> blacklistedFolder(MediaLibraryPtr ml, const std::string& mrl );
static std::shared_ptr<Folder> bannedFolder(MediaLibraryPtr ml, const std::string& mrl );
virtual int64_t id() const override;
virtual const std::string& mrl() const override;
......@@ -95,7 +95,7 @@ private:
// or the full path (including mrl scheme) for folders on non removable devices
std::string m_path;
const int64_t m_parent;
const bool m_isBlacklisted;
const bool m_isBanned;
const int64_t m_deviceId;
const bool m_isRemovable;
......
......@@ -1398,7 +1398,7 @@ bool MediaLibrary::setDiscoverNetworkEnabled( bool enabled )
Query<IFolder> MediaLibrary::entryPoints() const
{
static const std::string req = "FROM " + Folder::Table::Name + " WHERE parent_id IS NULL"
" AND is_blacklisted = 0";
" AND is_banned = 0";
return make_query<Folder, IFolder>( this, "*", req, "" );
}
......
......@@ -168,7 +168,7 @@ IMedia::Type::Unknown ) ),
#include "database/tables/Folder_v14.sql"
"INSERT INTO " + Folder::Table::Name + "("
"id_folder, path, parent_id, is_blacklisted, device_id, is_removable"
"id_folder, path, parent_id, is_banned, device_id, is_removable"
") "
"SELECT id_folder, path, parent_id, is_blacklisted, device_id, is_removable "
"FROM " + Folder::Table::Name + "_backup",
......
......@@ -3,7 +3,7 @@
"id_folder INTEGER PRIMARY KEY AUTOINCREMENT,"
"path TEXT,"
"parent_id UNSIGNED INTEGER,"
"is_blacklisted BOOLEAN NOT NULL DEFAULT 0,"
"is_banned BOOLEAN NOT NULL DEFAULT 0,"
"device_id UNSIGNED INTEGER,"
"is_removable BOOLEAN NOT NULL,"
......
......@@ -206,7 +206,7 @@ void DiscovererWorker::runRemove( const std::string& ep )
// method already handles the prior deletion
bool res;
if ( folder->isRootFolder() == false )
res = Folder::blacklist( m_ml, entryPoint );
res = Folder::ban( m_ml, entryPoint );
else
res = m_ml->deleteFolder( *folder );
if ( res == false )
......@@ -221,13 +221,13 @@ void DiscovererWorker::runRemove( const std::string& ep )
void DiscovererWorker::runBan( const std::string& entryPoint )
{
auto res = Folder::blacklist( m_ml, entryPoint );
auto res = Folder::ban( m_ml, entryPoint );
m_ml->getCb()->onEntryPointBanned( entryPoint, res );
}
void DiscovererWorker::runUnban( const std::string& entryPoint )
{
auto folder = Folder::blacklistedFolder( m_ml, entryPoint );
auto folder = Folder::bannedFolder( m_ml, entryPoint );
if ( folder == nullptr )
{
LOG_WARN( "Can't unban ", entryPoint, " as it wasn't banned" );
......
......@@ -98,7 +98,7 @@ bool FsDiscoverer::discover( const std::string& entryPoint )
}
catch ( sqlite::errors::ConstraintViolation& ex )
{
LOG_WARN( fsDirMrl, " discovery aborted (assuming blacklisted folder): ", ex.what() );
LOG_WARN( fsDirMrl, " discovery aborted (assuming banned folder): ", ex.what() );
}
catch ( DeviceRemovedException& )
{
......@@ -278,15 +278,15 @@ void FsDiscoverer::checkFolder( std::shared_ptr<fs::IDirectory> currentFolderFs,
}
catch ( sqlite::errors::ConstraintViolation& ex )
{
// Best attempt to detect a foreign key violation, indicating the parent folders have been
// deleted due to blacklisting
// Best attempt to detect a foreign key violation, indicating the
// parent folders have been deleted due to being banned
if ( strstr( ex.what(), "foreign key" ) != nullptr )
{
LOG_WARN( "Creation of a folder failed because the parent is non existing: ", ex.what(),
". Assuming it was deleted due to blacklisting" );
". Assuming it was deleted due to being banned" );
return;
}
LOG_WARN( "Creation of a duplicated folder failed: ", ex.what(), ". Assuming it was blacklisted" );
LOG_WARN( "Creation of a duplicated folder failed: ", ex.what(), ". Assuming it was banned" );
continue;
}
}
......
......@@ -48,7 +48,7 @@ namespace fs
DeviceLister::DeviceMap DeviceLister::listDevices() const
{
static const std::vector<std::string> deviceBlacklist = { "loop" };
static const std::vector<std::string> bannedDevice = { "loop" };
const std::string devPath = "/dev/disk/by-uuid/";
// Don't use fs::Directory to iterate, as it resolves the symbolic links automatically.
// We need the link name & what it points to.
......@@ -79,9 +79,9 @@ DeviceLister::DeviceMap DeviceLister::listDevices() const
throw std::runtime_error( err.str() );
}
auto deviceName = utils::file::fileName( linkPath );
if ( std::find_if( begin( deviceBlacklist ), end( deviceBlacklist ), [&deviceName]( const std::string& pattern ) {
if ( std::find_if( begin( bannedDevice ), end( bannedDevice ), [&deviceName]( const std::string& pattern ) {
return deviceName.length() >= pattern.length() && deviceName.find( pattern ) == 0;
}) != end( deviceBlacklist ) )
}) != end( bannedDevice ) )
continue;
auto uuid = result->d_name;
LOG_INFO( "Discovered device ", deviceName, " -> {", uuid, '}' );
......
......@@ -231,7 +231,7 @@ TEST_F( Folders, UpdateFile )
ASSERT_EQ( id, f->id() );
}
TEST_F( FoldersNoDiscover, Blacklist )
TEST_F( FoldersNoDiscover, Ban )
{
ml->banFolder( mock::FileSystemFactory::SubFolder );
cbMock->waitBanFolder();
......@@ -243,7 +243,7 @@ TEST_F( FoldersNoDiscover, Blacklist )
ASSERT_EQ( nullptr, f );
}
TEST_F( FoldersNoDiscover, DiscoverBlacklisted )
TEST_F( FoldersNoDiscover, DiscoverBanned )
{
ml->banFolder( mock::FileSystemFactory::Root );
cbMock->waitBanFolder();
......@@ -255,7 +255,7 @@ TEST_F( FoldersNoDiscover, DiscoverBlacklisted )
ASSERT_EQ( nullptr, f );
}
TEST_F( Folders, BlacklistAfterDiscovery )
TEST_F( Folders, BanAfterDiscovery )
{
auto f = std::static_pointer_cast<Folder>( ml->folder( mock::FileSystemFactory::SubFolder ) );
ASSERT_NE( nullptr, f );
......@@ -268,7 +268,7 @@ TEST_F( Folders, BlacklistAfterDiscovery )
ASSERT_EQ( nullptr, f2 );
}
TEST_F( FoldersNoDiscover, RemoveFromBlacklist )
TEST_F( FoldersNoDiscover, RemoveFromBannedList )
{
ml->banFolder( mock::FileSystemFactory::SubFolder );
cbMock->waitBanFolder();
......@@ -289,7 +289,7 @@ TEST_F( FoldersNoDiscover, RemoveFromBlacklist )
ASSERT_NE( nullptr, f );
}
TEST_F( FoldersNoDiscover, BlacklistTwice )
TEST_F( FoldersNoDiscover, BanTwice )
{
ml->banFolder( mock::FileSystemFactory::SubFolder );
cbMock->waitBanFolder();
......@@ -297,7 +297,7 @@ TEST_F( FoldersNoDiscover, BlacklistTwice )
cbMock->waitBanFolder();
}
TEST_F( FoldersNoDiscover, BlacklistNonExistant )
TEST_F( FoldersNoDiscover, BanNonExistant )
{
ml->banFolder( "foo/bar/otters" );
cbMock->waitBanFolder();
......@@ -428,7 +428,7 @@ TEST_F( Folders, RemoveEntryPoint )
ml->reload();
// Ensure it wasn't re-discovered, ie. that it was properly blacklisted
// Ensure it wasn't re-discovered, ie. that it was properly banned
auto media2 = ml->files();
ASSERT_EQ( media.size(), media2.size() );
}
......
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