Handle file errors when device path gets unbound
occ-control was asserting when the hwmon path would get removed due to
device being unbound. This change will gracefully handle the path
getting removed / added back.
Tested on Raininer by unbind/bind of devices:
echo occ-hwmon.2 > /sys/bus/platform/drivers/occ-hwmon/unbind
echo occ-hwmon.2 > /sys/bus/platform/drivers/occ-hwmon/bind
Change-Id: I46fd2c2c54868ffb8183d3dc49cd0c2751165d3b
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/occ_device.hpp b/occ_device.hpp
index 97bdceb..3c11d13 100644
--- a/occ_device.hpp
+++ b/occ_device.hpp
@@ -283,17 +283,8 @@
*
* @return path to the file or empty path if not found
*/
- fs::path getFilenameByRegex(fs::path basePath, const std::regex& expr) const
- {
- for (auto& file : fs::directory_iterator(basePath))
- {
- if (std::regex_search(file.path().string(), expr))
- {
- return file;
- }
- }
- return fs::path{};
- }
+ fs::path getFilenameByRegex(fs::path basePath,
+ const std::regex& expr) const;
};
} // namespace occ