add clang-tidy
This commit implements a clang-tidy file, and makes some changes to get
it to pass. Most changes are naming or mechanical in nature.
Tested:
Clang-tidy now passes.
Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: Ia441e4801b6c8725421d160c531c5df141f255d4
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 899ec98..5217129 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -14,8 +14,7 @@
// limitations under the License.
*/
-#include "Utils.hpp"
-
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/container/flat_map.hpp>
#include <sdbusplus/asio/connection.hpp>
@@ -130,6 +129,14 @@
bool getSensorConfiguration(
const std::string& type,
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+ ManagedObjectType& resp)
+{
+ return getSensorConfiguration(type, dbusConnection, resp, false);
+}
+
+bool getSensorConfiguration(
+ const std::string& type,
+ const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
ManagedObjectType& resp, bool useCache)
{
static ManagedObjectType managedObj;
@@ -182,25 +189,31 @@
return true;
}
-bool findFiles(const fs::path dirPath, const std::string& matchString,
- std::vector<fs::path>& foundPaths, unsigned int symlinkDepth)
+bool findFiles(const fs::path& dirPath, const std::string& matchString,
+ std::vector<fs::path>& foundPaths, int symlinkDepth)
{
if (!fs::exists(dirPath))
+ {
return false;
+ }
std::regex search(matchString);
std::smatch match;
- for (auto& p : fs::recursive_directory_iterator(dirPath))
+ for (auto p = fs::recursive_directory_iterator(
+ dirPath, fs::directory_options::follow_directory_symlink);
+ p != fs::recursive_directory_iterator(); ++p)
{
- std::string path = p.path().string();
- if (!is_directory(p))
+ std::string path = p->path().string();
+ if (!is_directory(*p))
{
if (std::regex_search(path, match, search))
- foundPaths.emplace_back(p.path());
+ {
+ foundPaths.emplace_back(p->path());
+ }
}
- else if (is_symlink(p) && symlinkDepth)
+ if (p.depth() >= symlinkDepth)
{
- findFiles(p.path(), matchString, foundPaths, symlinkDepth - 1);
+ p.disable_recursion_pending();
}
}
return true;
@@ -328,7 +341,7 @@
{
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "Timer error " << ec.message() << "\n";
return;
@@ -390,15 +403,15 @@
std::filesystem::path p(path);
std::vector<Association> associations;
- associations.push_back(
- Association("chassis", "all_sensors", p.parent_path().string()));
+ associations.emplace_back("chassis", "all_sensors",
+ p.parent_path().string());
association->register_property("Associations", associations);
association->initialize();
}
}
void setInventoryAssociation(
- std::shared_ptr<sdbusplus::asio::dbus_interface> association,
+ const std::shared_ptr<sdbusplus::asio::dbus_interface>& association,
const std::string& path,
const std::vector<std::string>& chassisPaths = std::vector<std::string>())
{
@@ -408,13 +421,12 @@
std::vector<Association> associations;
std::string objPath(p.parent_path().string());
- associations.push_back(Association("inventory", "sensors", objPath));
- associations.push_back(Association("chassis", "all_sensors", objPath));
+ associations.emplace_back("inventory", "sensors", objPath);
+ associations.emplace_back("chassis", "all_sensors", objPath);
for (const std::string& chassisPath : chassisPaths)
{
- associations.push_back(
- Association("chassis", "all_sensors", chassisPath));
+ associations.emplace_back("chassis", "all_sensors", chassisPath);
}
association->register_property("Associations", associations);
@@ -423,8 +435,8 @@
}
void createInventoryAssoc(
- std::shared_ptr<sdbusplus::asio::connection> conn,
- std::shared_ptr<sdbusplus::asio::dbus_interface> association,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::shared_ptr<sdbusplus::asio::dbus_interface>& association,
const std::string& path)
{
if (!association)