diff options
author | Matt Spinler <spinler@us.ibm.com> | 2019-03-15 12:29:26 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2019-03-15 12:29:26 -0500 |
commit | 85ba64a653de3ede60a228f42f62dcf1ab55ca17 (patch) | |
tree | 7a740ff24a179aef7870275265239cb10928bf82 | |
parent | 9e997b4da98725401769ef82fe26e11c46a059d9 (diff) | |
download | phosphor-hwmon-85ba64a653de3ede60a228f42f62dcf1ab55ca17.tar.gz phosphor-hwmon-85ba64a653de3ede60a228f42f62dcf1ab55ca17.zip |
Don't std::filesystem::path::/= an absolute path
Unlike std::experimental::filesystem::path, with
std::filesystem::path, the /= operator will turn an append
of an absolute path (starts with a '/') into a '='.
So, ensure the paths aren't absolute.
Change-Id: Ie8fb9d056042e277415e8ea0eb29d094a2665611
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rw-r--r-- | sysfs.cpp | 16 | ||||
-rw-r--r-- | sysfs.hpp | 4 |
2 files changed, 16 insertions, 4 deletions
@@ -162,10 +162,16 @@ std::string findCalloutPath(const std::string& instancePath) return emptyString; } -std::string findHwmonFromOFPath(const std::string& ofNode) +std::string findHwmonFromOFPath(std::string ofNode) { static constexpr auto hwmonRoot = "/sys/class/hwmon"; + // Can't append an absolute path + if (!ofNode.empty() && (ofNode.front() == '/')) + { + ofNode = ofNode.substr(1); + } + fs::path fullOfPath{ofRoot}; fullOfPath /= ofNode; @@ -203,8 +209,14 @@ std::string findHwmonFromOFPath(const std::string& ofNode) return emptyString; } -std::string findHwmonFromDevPath(const std::string& devPath) +std::string findHwmonFromDevPath(std::string devPath) { + // Can't append an absolute path + if (!devPath.empty() && devPath.front() == '/') + { + devPath = devPath.substr(1); + } + fs::path p{"/sys"}; p /= devPath; p /= "hwmon"; @@ -50,7 +50,7 @@ std::string findPhandleMatch(const std::string& iochanneldir, * @returns[in] - The hwmon instance path or an empty * string if no match is found. */ -std::string findHwmonFromOFPath(const std::string& ofNode); +std::string findHwmonFromOFPath(std::string ofNode); /** @brief Find hwmon instances from a device path * @@ -63,7 +63,7 @@ std::string findHwmonFromOFPath(const std::string& ofNode); * @return - The hwmon instance path or an empty * string if no match is found. */ -std::string findHwmonFromDevPath(const std::string& devPath); +std::string findHwmonFromDevPath(std::string devPath); /** @brief Return the path to use for a call out. * |