Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy fixes #2978

Merged
merged 14 commits into from
Jan 23, 2024
2 changes: 1 addition & 1 deletion src/action_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ActionRequest::ActionRequest(std::shared_ptr<UpnpXMLBuilder> xmlBuilder, std::sh
{
auto ctrlPtIPAddr = std::make_shared<GrbNet>(UpnpActionRequest_get_CtrlPtIPAddr(upnpRequest));
std::string userAgent = UpnpActionRequest_get_Os_cstr(upnpRequest);
quirks = std::make_unique<Quirks>(xmlBuilder, clients, ctrlPtIPAddr, userAgent);
quirks = std::make_unique<Quirks>(std::move(xmlBuilder), clients, ctrlPtIPAddr, userAgent);
}

std::string ActionRequest::getActionName() const
Expand Down
5 changes: 1 addition & 4 deletions src/config/config_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,8 @@ std::shared_ptr<pugi::xml_node> ConfigGenerator::setVector(config_option_t optio
auto nodeKey = ConfigDefinition::mapConfigOption(cs->nodeOption);
for (auto&& value : cs->getXmlContent({})) {
setValue(fmt::format("{}/{}/", cs->xpath, nodeKey), "", true);
std::size_t index = 0;
for (auto&& [key, val] : value) {
for (auto&& [key, val] : value)
setValue(fmt::format("{}/{}/attribute::{}", cs->xpath, nodeKey, key), val);
++index;
}
}
return generated[cs->xpath];
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/config_option_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
template <class Enum>
class EnumOption : public ConfigOption {
public:
explicit EnumOption(Enum option, const std::string& optionString)
explicit EnumOption(Enum option, std::string optionString)
: option(option)
, optionString(optionString)
, optionString(std::move(optionString))
{
}

std::string getOption() const override { return optionString.length() == 0 ? fmt::format("{}", option) : optionString; }

Enum getEnumOption() const { return option; }

static Enum getEnumOption(const std::shared_ptr<Config> config, config_option_t option)
static Enum getEnumOption(const std::shared_ptr<Config>& config, config_option_t option)
{
auto optionValue = config->getConfigOption(option);
auto optionEnumValue = std::dynamic_pointer_cast<EnumOption<Enum>>(optionValue);
Expand Down
12 changes: 6 additions & 6 deletions src/config/config_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ class Option : public ConfigOption {

class IntOption : public ConfigOption {
public:
explicit IntOption(IntOptionType option, const std::string& optionString = "")
explicit IntOption(IntOptionType option, std::string optionString = "")
: option(option)
, optionString(optionString)
, optionString(std::move(optionString))
{
}

Expand All @@ -155,9 +155,9 @@ class IntOption : public ConfigOption {

class UIntOption : public ConfigOption {
public:
explicit UIntOption(UIntOptionType option, const std::string& optionString = "")
explicit UIntOption(UIntOptionType option, std::string optionString = "")
: option(option)
, optionString(optionString)
, optionString(std::move(optionString))
{
}

Expand All @@ -172,9 +172,9 @@ class UIntOption : public ConfigOption {

class LongOption : public ConfigOption {
public:
explicit LongOption(LongOptionType option, const std::string& optionString = "")
explicit LongOption(LongOptionType option, std::string optionString = "")
: option(option)
, optionString(optionString)
, optionString(std::move(optionString))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/config_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ConfigSetup {

bool checkValue(std::string& optValue) const
{
return !(rawCheck && !rawCheck(optValue));
return !rawCheck || rawCheck(optValue);
}
const char* getHelp() const { return help; }
std::shared_ptr<ConfigOption> getValue() const { return optionValue; }
Expand Down
8 changes: 4 additions & 4 deletions src/config/setup/config_setup_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

template <typename T, class OptionClass>
class ConfigIntegerSetup : public ConfigSetup {
static_assert(std::is_integral<T>::value, "Integral required.");
static_assert(std::is_integral_v<T>, "Integral required.");

public:
using IntCheckFunction = std::function<bool(T value)>;
Expand Down Expand Up @@ -128,8 +128,8 @@ bool CheckProfileNumberValue(std::string& value);
bool CheckImageQualityValue(IntOptionType value);
bool CheckPortValue(UIntOptionType value);

typedef ConfigIntegerSetup<IntOptionType, IntOption> ConfigIntSetup;
typedef ConfigIntegerSetup<UIntOptionType, UIntOption> ConfigUIntSetup;
typedef ConfigIntegerSetup<LongOptionType, LongOption> ConfigLongSetup;
using ConfigIntSetup = ConfigIntegerSetup<IntOptionType, IntOption>;
using ConfigUIntSetup = ConfigIntegerSetup<UIntOptionType, UIntOption>;
using ConfigLongSetup = ConfigIntegerSetup<LongOptionType, LongOption>;

#endif // __CONFIG_SETUP_INT_H__
1 change: 1 addition & 0 deletions src/config/setup/config_setup_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ bool ConfigVectorSetup::createOptionFromNode(const pugi::xml_node& optValue, std
if (optValue) {
const auto dictNodes = optValue.select_nodes(ConfigDefinition::mapConfigOption(nodeOption));
std::vector<std::string> attrList;
attrList.reserve(optionList.size());
for (auto& opt : optionList) {
attrList.push_back(ConfigDefinition::removeAttribute(opt));
}
Expand Down
2 changes: 1 addition & 1 deletion src/content/autoscan_inotify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ int AutoscanInotify::addMoveWatch(const fs::path& path, int removeWd, int parent

// add move watch
auto watch = std::make_shared<WatchMove>(removeWd);
wdObj->addWatch(move(watch));
wdObj->addWatch(std::move(watch));
}
return wd;
}
Expand Down
4 changes: 2 additions & 2 deletions src/content/cm_task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ void CMAddFileTask::run()
}

CMRemoveObjectTask::CMRemoveObjectTask(std::shared_ptr<ContentManager> content, std::shared_ptr<AutoscanDirectory> adir,
std::shared_ptr<CdsObject> object, const fs::path& path, bool rescanResource, bool all)
std::shared_ptr<CdsObject> object, fs::path path, bool rescanResource, bool all)
: GenericTask(ContentManagerTask)
, content(std::move(content))
, adir(std::move(adir))
, object(std::move(object))
, path(path)
, path(std::move(path))
, all(all)
, rescanResource(rescanResource)
{
Expand Down
2 changes: 1 addition & 1 deletion src/content/cm_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CMRemoveObjectTask : public GenericTask {

public:
CMRemoveObjectTask(std::shared_ptr<ContentManager> content, std::shared_ptr<AutoscanDirectory> adir,
std::shared_ptr<CdsObject> object, const fs::path& path, bool rescanResource, bool all);
std::shared_ptr<CdsObject> object, fs::path path, bool rescanResource, bool all);
void run() override;
};

Expand Down
42 changes: 20 additions & 22 deletions src/content/content_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void ContentManager::run()
continue;
}
}
for (auto dir : config->getAutoscanListOption(CFG_IMPORT_AUTOSCAN_INOTIFY_LIST)) {
for (const auto& dir : config->getAutoscanListOption(CFG_IMPORT_AUTOSCAN_INOTIFY_LIST)) {
fs::path path = dir->getLocation();
if (fs::is_directory(path)) {
dir->setObjectID(ensurePathExistence(path));
Expand Down Expand Up @@ -413,7 +413,7 @@ std::shared_ptr<CdsObject> ContentManager::createSingleItem(
bool processExisting,
bool firstChild,
const std::shared_ptr<AutoscanDirectory>& adir,
std::shared_ptr<CMAddFileTask> task)
const std::shared_ptr<CMAddFileTask>& task)
{
auto obj = checkDatabase ? database->findObjectByPath(dirEnt.path()) : nullptr;
bool isNew = false;
Expand Down Expand Up @@ -474,27 +474,25 @@ std::shared_ptr<CdsObject> ContentManager::_addFile(const fs::directory_entry& d
getImportService(asSetting.adir)->doImport(dirEnt.path(), asSetting, currentContent, task);

return getImportService(asSetting.adir)->getObject(dirEnt.path());
} else {
// checkDatabase, don't process existing
std::shared_ptr<CdsContainer> parent;
auto parentObject = database->findObjectByPath(dirEnt.path().parent_path(), DbFileType::Directory);
if (parentObject && parentObject->isContainer())
parent = std::dynamic_pointer_cast<CdsContainer>(parentObject);
auto obj = createSingleItem(dirEnt, parent, rootPath, asSetting.followSymlinks, true, false, false, asSetting.adir, task);
if (!obj) // object ignored
return obj;

if (asSetting.recursive && obj->isContainer()) {
addRecursive(asSetting.adir, dirEnt, std::dynamic_pointer_cast<CdsContainer>(obj), asSetting.followSymlinks, asSetting.hidden, task);
}
}
// checkDatabase, don't process existing
std::shared_ptr<CdsContainer> parent;
auto parentObject = database->findObjectByPath(dirEnt.path().parent_path(), DbFileType::Directory);
if (parentObject && parentObject->isContainer())
parent = std::dynamic_pointer_cast<CdsContainer>(parentObject);
auto obj = createSingleItem(dirEnt, parent, rootPath, asSetting.followSymlinks, true, false, false, asSetting.adir, task);
if (!obj) // object ignored
return obj;

if (asSetting.rescanResource && obj->hasResource(ContentHandler::RESOURCE)) {
std::string parentPath = dirEnt.path().parent_path();
updateAttachedResources(asSetting.adir, obj, parentPath, true);
}
if (asSetting.recursive && obj->isContainer())
addRecursive(asSetting.adir, dirEnt, std::dynamic_pointer_cast<CdsContainer>(obj), asSetting.followSymlinks, asSetting.hidden, task);

return obj;
if (asSetting.rescanResource && obj->hasResource(ContentHandler::RESOURCE)) {
std::string parentPath = dirEnt.path().parent_path();
updateAttachedResources(asSetting.adir, obj, parentPath, true);
}

return obj;
}

bool ContentManager::updateAttachedResources(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& parentPath, bool all)
Expand Down Expand Up @@ -531,7 +529,7 @@ bool ContentManager::updateAttachedResources(const std::shared_ptr<AutoscanDirec
return parentRemoved;
}

std::vector<int> ContentManager::_removeObject(const std::shared_ptr<AutoscanDirectory>& adir, std::shared_ptr<CdsObject> obj, const fs::path& path, bool rescanResource, bool all)
std::vector<int> ContentManager::_removeObject(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& path, bool rescanResource, bool all)
{
if (!obj || obj->getID() == INVALID_OBJECT_ID)
return {};
Expand Down Expand Up @@ -1453,7 +1451,7 @@ void ContentManager::invalidateTask(unsigned int taskID, task_owner_t taskOwner)
#endif
}

std::vector<int> ContentManager::removeObject(const std::shared_ptr<AutoscanDirectory>& adir, std::shared_ptr<CdsObject> obj, const fs::path& path, bool rescanResource, bool async, bool all)
std::vector<int> ContentManager::removeObject(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& path, bool rescanResource, bool async, bool all)
{
if (async) {
auto self = shared_from_this();
Expand Down
6 changes: 3 additions & 3 deletions src/content/content_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ContentManager : public Timer::Subscriber, public std::enable_shared_from_
bool lowPriority = false, bool cancellable = true);

int ensurePathExistence(const fs::path& path) const;
std::vector<int> removeObject(const std::shared_ptr<AutoscanDirectory>& adir, std::shared_ptr<CdsObject> obj, const fs::path& path, bool rescanResource, bool async = true, bool all = false);
std::vector<int> removeObject(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& path, bool rescanResource, bool async = true, bool all = false);

/// \brief Updates an object in the database using the given parameters.
/// \param objectID ID of the object to update
Expand Down Expand Up @@ -270,14 +270,14 @@ class ContentManager : public Timer::Subscriber, public std::enable_shared_from_
const std::shared_ptr<CMAddFileTask>& task = nullptr);

std::shared_ptr<ImportService> getImportService(const std::shared_ptr<AutoscanDirectory>& adir);
std::vector<int> _removeObject(const std::shared_ptr<AutoscanDirectory>& adir, std::shared_ptr<CdsObject> obj, const fs::path& path, bool rescanResource, bool all);
std::vector<int> _removeObject(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& path, bool rescanResource, bool all);
void cleanupTasks(const fs::path& path);

void scanDir(const std::shared_ptr<AutoscanDirectory>& dir, bool updateUI);
void _rescanDirectory(const std::shared_ptr<AutoscanDirectory>& adir, int containerID, const std::shared_ptr<GenericTask>& task = nullptr);
/* for recursive addition */
void addRecursive(std::shared_ptr<AutoscanDirectory>& adir, const fs::directory_entry& subDir, const std::shared_ptr<CdsContainer>& parentContainer, bool followSymlinks, bool hidden, const std::shared_ptr<CMAddFileTask>& task);
std::shared_ptr<CdsObject> createSingleItem(const fs::directory_entry& dirEnt, const std::shared_ptr<CdsContainer>& parent, const fs::path& rootPath, bool followSymlinks, bool checkDatabase, bool processExisting, bool firstChild, const std::shared_ptr<AutoscanDirectory>& adir, std::shared_ptr<CMAddFileTask> task);
std::shared_ptr<CdsObject> createSingleItem(const fs::directory_entry& dirEnt, const std::shared_ptr<CdsContainer>& parent, const fs::path& rootPath, bool followSymlinks, bool checkDatabase, bool processExisting, bool firstChild, const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CMAddFileTask>& task);
bool updateAttachedResources(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& parentPath, bool all);
static void invalidateAddTask(const std::shared_ptr<GenericTask>& t, const fs::path& path);

Expand Down
25 changes: 12 additions & 13 deletions src/content/import_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void ImportService::run(std::shared_ptr<ContentManager> content, std::shared_ptr
this->content = std::move(content);
if (autoScan) {
this->autoscanDir = std::move(autoScan);
this->rootPath = path;
this->rootPath = std::move(path);
}
}

Expand Down Expand Up @@ -294,7 +294,7 @@ void ImportService::readDir(const fs::path& location, AutoScanSetting settings)
log_debug("end {}", location.string());
}

void ImportService::cacheState(const fs::path& entryPath, const fs::directory_entry& dirEntry, ImportState state, std::chrono::seconds mtime, std::shared_ptr<CdsObject> cdsObject)
void ImportService::cacheState(const fs::path& entryPath, const fs::directory_entry& dirEntry, ImportState state, std::chrono::seconds mtime, const std::shared_ptr<CdsObject>& cdsObject)
{
if (contentStateCache.find(entryPath) == contentStateCache.end()) {
contentStateCache[entryPath] = std::make_shared<ContentState>(dirEntry, state, mtime, cdsObject);
Expand Down Expand Up @@ -359,14 +359,13 @@ bool ImportService::isHiddenFile(const fs::path& entryPath, bool isDirectory, co
auto noMediaFile = (isDirectory) ? entryPath / noMediaName : entryPath.parent_path() / noMediaName;
if (contentStateCache.find(noMediaFile) != contentStateCache.end()) {
return contentStateCache[entryPath]->getState() != ImportState::Broken; // broken means: file not found
}
auto noMediaEntry = fs::directory_entry(noMediaFile, ec);
if (!noMediaEntry.exists(ec) || ec) {
cacheState(noMediaEntry, noMediaEntry, ImportState::Broken, toSeconds(dirEntry.last_write_time(ec)));
} else {
auto noMediaEntry = fs::directory_entry(noMediaFile, ec);
if (!noMediaEntry.exists(ec) || ec) {
cacheState(noMediaEntry, noMediaEntry, ImportState::Broken, toSeconds(dirEntry.last_write_time(ec)));
} else {
// if file exists it will be automatically created
return true;
}
// if file exists it will be automatically created
return true;
}
}
return false;
Expand Down Expand Up @@ -504,7 +503,7 @@ void ImportService::createItems(AutoScanSetting& settings)

std::pair<bool, std::shared_ptr<CdsObject>> ImportService::createSingleItem(const fs::directory_entry& dirEntry) // ToDo: Use StateEntry here
{
auto objectPath = dirEntry.path();
const auto& objectPath = dirEntry.path();

/* retrieve information about item and decide if it should be included */
auto [skip, mimetype] = mime->getMimeType(objectPath, MIMETYPE_DEFAULT);
Expand Down Expand Up @@ -551,7 +550,7 @@ std::pair<bool, std::shared_ptr<CdsObject>> ImportService::createSingleItem(cons
return { skip, item };
}

void ImportService::updateSingleItem(const fs::directory_entry& dirEntry, std::shared_ptr<CdsItem> item, const std::string& mimetype)
void ImportService::updateSingleItem(const fs::directory_entry& dirEntry, const std::shared_ptr<CdsItem>& item, const std::string& mimetype)
{
auto mTime = toSeconds(dirEntry.last_write_time(ec));
item->setMTime(mTime);
Expand All @@ -575,7 +574,7 @@ void ImportService::fillLayout(const std::shared_ptr<GenericTask>& task)
/// \param object used to make code compatible with legacy scan
void ImportService::fillSingleLayout(const std::shared_ptr<ContentState>& state, std::shared_ptr<CdsObject> object, const std::shared_ptr<CdsContainer>& parent, const std::shared_ptr<GenericTask>& task)
{
std::shared_ptr<CdsObject> cdsObject = state ? state->getObject() : object;
std::shared_ptr<CdsObject> cdsObject = state ? state->getObject() : std::move(object);

if (cdsObject && cdsObject->isItem() && layout) {
try {
Expand Down Expand Up @@ -604,7 +603,7 @@ void ImportService::fillSingleLayout(const std::shared_ptr<ContentState>& state,
#ifdef HAVE_JS
try {
if (playlistParserScript && contentType == CONTENT_TYPE_PLAYLIST)
playlistParserScript->processPlaylistObject(cdsObject, std::move(task), rootPath);
playlistParserScript->processPlaylistObject(cdsObject, task, rootPath);
} catch (const std::runtime_error& e) {
log_error("{}", e.what());
}
Expand Down
16 changes: 8 additions & 8 deletions src/content/import_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ class ContentState {
std::shared_ptr<CdsContainer> parentObject;

public:
ContentState(const fs::directory_entry& dirEntry, ImportState state, std::chrono::seconds mtime = std::chrono::seconds::zero(), std::shared_ptr<CdsObject> cdsObject = nullptr)
ContentState(fs::directory_entry dirEntry, ImportState state, std::chrono::seconds mtime = std::chrono::seconds::zero(), std::shared_ptr<CdsObject> cdsObject = nullptr)
: state(state)
, dirEntry(dirEntry)
, dirEntry(std::move(dirEntry))
, mtime(mtime)
, cdsObject(cdsObject)
, cdsObject(std::move(cdsObject))
{
}

void setObject(ImportState state, std::shared_ptr<CdsObject> cdsObject)
{
this->state = state;
this->cdsObject = cdsObject;
this->cdsObject = std::move(cdsObject);
}
void setFirstObject(std::shared_ptr<CdsObject> firstObject)
{
this->firstObject = firstObject;
this->firstObject = std::move(firstObject);
}
void setParentObject(std::shared_ptr<CdsContainer> parentObject)
{
this->parentObject = parentObject;
this->parentObject = std::move(parentObject);
}
std::shared_ptr<CdsObject> getObject() { return cdsObject; }
std::shared_ptr<CdsObject> getFirstObject() { return firstObject; }
Expand Down Expand Up @@ -182,13 +182,13 @@ class ImportService {
void readFile(const fs::path& location);
void createContainers(int parentContainerId, AutoScanSetting& settings);
void createItems(AutoScanSetting& settings);
void updateSingleItem(const fs::directory_entry& dirEntry, std::shared_ptr<CdsItem> item, const std::string& mimetype);
void updateSingleItem(const fs::directory_entry& dirEntry, const std::shared_ptr<CdsItem>& item, const std::string& mimetype);
void fillLayout(const std::shared_ptr<GenericTask>& task);
void updateFanArt();
void assignFanArt(const std::shared_ptr<CdsContainer>& container, const std::shared_ptr<CdsObject>& refObj, int count);
void removeHidden(AutoScanSetting& settings);

void cacheState(const fs::path& entryPath, const fs::directory_entry& dirEntry, ImportState state, std::chrono::seconds mtime = std::chrono::seconds::zero(), std::shared_ptr<CdsObject> cdsObject = nullptr);
void cacheState(const fs::path& entryPath, const fs::directory_entry& dirEntry, ImportState state, std::chrono::seconds mtime = std::chrono::seconds::zero(), const std::shared_ptr<CdsObject>& cdsObject = nullptr);

public:
ImportService(std::shared_ptr<Context> context);
Expand Down